日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C 语言的io流

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C 语言的io流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

寫入:
? ? CString strCMD = L“E:\CompressionRar\CompressionRar\Bin\Release\abc.txt”;
? ? USES_CONVERSION;

? ? std::string strFptxt(W2A(strCMD));

? ? FILE *fp=fopen(strTextPath.c_str(), "at");
? ? fprintf(fp,"%s\n", strFptxt.c_str());

? ? fclose(fp);?

讀出:
? //UniCode CString 轉 char*

? ? ? ?USES_CONVERSION;??
? char * cFileName = T2A(pFileName);

? ??char cTxt[100] = {0};

? ?FILE *fp=fopen(strTextPath.c_str(), "rt");

? ?while(fscanf(fp,"%s",cTxt) != EOF)??

? ?{
?CString abc(cTxt);

AfxMessageBox(abc);

? ?}

? ?fclose(fp);?

刪除:
? ?第一種方法:定義一個文件類對象來操作

??? CFile??? TempFile;???

??? TempFile.Remove(指定文件名);

?

?

?第二種方法:

?

? ? ? ? ? ? ? DeleteFile("c:\\abc\\test.exe ");//MFC框架中可直接調用此函數?

刪除目錄

_rmdir()

DeleteDirectory(sTempDir)

RemoveDirectory(sTempDir)?

?

?

?

?

?

?

?

?

?

 

?

//刪除文件夾目錄(非空)

?

方法一 

bool DeleteDirectory( CString DirName)

{

AfxMessageBox("執行刪除文件夾:"+DirName);

?

CString PUBPATH;

PUBPATH=DirName;

?

CFileFind tempFind;

DirName+="\\*.*";

BOOL IsFinded=(BOOL)tempFind.FindFile(DirName);

while(IsFinded)

{

IsFinded=(BOOL)tempFind.FindNextFile();

if(!tempFind.IsDots())

{

?

CString strDirName;

strDirName+=PUBPATH;

strDirName+="\\";

strDirName+=tempFind.GetFileName();

AfxMessageBox("strDirName :"+strDirName);

?

if(tempFind.IsDirectory())

{

//strDirName += PUBPATH;

DeleteDirectory(strDirName);

}

else

{

SetFileAttributes(strDirName,FILE_ATTRIBUTE_NORMAL); //去掉文件的系統和隱藏屬性

DeleteFile(strDirName);

}

}

}

tempFind.Close();

if(!RemoveDirectory(PUBPATH))

{

return false ;

}

AfxMessageBox("文件夾刪除成功...");

return true;

}

?

?

?

?

方法二


bool DeleteDirectory( char* DirName)
{
HANDLE hFirstFile = NULL;?
WIN32_FIND_DATA FindData;?

char currdir[MAX_PATH] = {0};
sprintf(currdir, "%s\\*.*", DirName);

hFirstFile = ::FindFirstFile(currdir, &FindData);?
if( hFirstFile == INVALID_HANDLE_VALUE )?
?? return false;

BOOL bRes = true;

while(bRes)?
{?
?? bRes = ::FindNextFile(hFirstFile, &FindData);

?? if( (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) //發現目錄
?? {
??? if( !strcmp(FindData.cFileName, ".") || !strcmp(FindData.cFileName, "..") ) //.或..
???? continue;
??? else
??? {
???? char tmppath[MAX_PATH] = {0};
???? sprintf(tmppath, "%s\\%s", DirName, FindData.cFileName);
????
???? DeleteDirectory(tmppath);
??? }
?? }
?? else?????????????? //發現文件
?? {
??? char tmppath[MAX_PATH] = {0};
??? sprintf(tmppath, "%s\\%s", DirName, FindData.cFileName);
??? ::DeleteFile(tmppath);????
?? }
}?
::FindClose(hFirstFile);
if(!RemoveDirectory(DirName))
{
?? return false ;
}
return true;
}

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的C 语言的io流的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。