vc中怎么给文本文件后添加文字(CString)

vc中怎么给文本文件后添加文字(CString)
2025-01-20 00:56:23
推荐回答(2个)
回答1:

CStdioFile stdFile;
CString strList = "";
CString strExcel = "";
CString strTemp = "";
stdFile.Open(sExcelFile, CFile::modeCreate | CFile::modeRead | CFile::modeNoTruncate | CFile::typeText);
while(stdFile.ReadString(strTemp))
strExcel = strExcel + strTemp + "\n";
stdFile.Close();
stdFile.Open(sExcelFile, CFile::modeWrite | CFile::typeText);
for (int i = 0; i < pList->GetItemCount(); i ++)
{
strList.Empty();
for (int j = 0; j < pList->GetHeaderCtrl()->GetItemCount(); j++)
{
strTemp = pList->GetItemText(i, j);
strList = strList + strTemp + "\t";
}
strExcel = strExcel + strList + "\n";
}
stdFile.WriteString((LPCTSTR)strExcel);
stdFile.Close();

回答2:

#include
CString temp = "123";
FILE *fp;
fp = fopen("文件路径", "a+");
//以追加方式打开文件
if(fp != NULL)
{
fprintf(fp, "%s", temp);
fclose(fp);
}