怎样用C++去再一个txt文件中读出数据 并且把读出的数据按一定的顺序写入另外一个txt文件

2024-12-20 18:47:04
推荐回答(2个)
回答1:

CFile m_File;
m_File.Open(A);
m_File.Seek()
m_File.Read(A);
m_File.Close(A);
m_File.Open(B);
m_File.Seek()
m_File.Write(B);
m_File.Close(B);
参数自己参考msdn.

回答2:

CStdioFile file;
if(file.Open(filename1,CFile::modeRead))
{
int numarray=0;
CString str;BOOL b=FALSE;
do
{
b=file.ReadString(str);
filearray.SetAtGrow(numarray,str);
numarray++;
}while(b);

file.Close();
}

CStdioFile file;
file.Open(filename2,CFile::modeWrite|CFile::modeCreate);
for(int i=0;i {
CString zx=filearray.GetAt(i);
LPCTSTR lpctstr=zx.GetBuffer(1+zx.GetLength());
file.WriteString(lpctstr);
}

file.Close();