月亮摄影作品:VC++中写一个文本文件?

来源:百度文库 编辑:中科新闻网 时间:2024/05/08 19:37:45
有两个字符串:
CString str1="How are you";
CString str2="I am fine";
要写到一个文本文件hello.txt中去。怎样用CreateFile()函数来建立这个文本文件,然后怎样把这两个串写到文本文件中去(中间换行)?给出代码好吗?

#include<fstream.h>

void CreateFile(){
CString str1="How are you";
CString str2="I am fine";
ofstream a("hello.txt");
a<<str1<<endl<<str2<<endl;
}

用CFile类
CFile Myfile;
查MSDN