- // use C to write into file
- FILE *pFile=fopen("1.txt","w");
- CString strTemp = "hello world!";
- fwrite(strTemp,1,strTemp.GetLength(),pFile);
- fflush(pFile);
- fclose(pFile);
- // use C++ to write into file
- ofstream ofs("2.txt");
- CString str = "Use C++.Hello World !";
- ofs.write(str,str.GetLength());
- ofs.flush();
- ofs.close();
- // use MFC to write into file
- CString str = "Use CFile,Hello World !";
- CFile file("3.txt",CFile::modeCreate | CFile::modeWrite);
- file.Write(str,str.GetLength());
- file.Flush();
- file.Close();
转载于:https://www.cnblogs.com/liuweilinlin/archive/2012/07/19/2598713.html