#include
#include
using namespace std;
void main()
{
ofstream ofile;
ofile.open("c:\\helloworld.txt");
cout << "Hello World!" << endl;
ofile << "Hello World!" << endl;
ofile.close();
}
在这行代码 ofile.open("c:\\helloworld.txt");
将路径输入双引号内即可。
用
http://www.cplusplus.com/reference/fstream/ofstream/
参考代码
#include
int main()
{
std::ofstream fout("C:\helloworld\a.txt");
fout << "Hello World!";
fout.close();
return 0;
}
const char *fileName = "C:\\helloworld\\test.txt";
ofstream ofs(fileName);
if(!ofs) {
cout << "Cannot open file.\n";
return 1;
}
ofs << 10 << " " << 123.23 << "\n";
ofs << "This is a text.";
ofs.close();