#include <fstream>
std::ofstream fileOutput("filename");
fileOutput << "write some data to this file stream. \n";
fileOutput.close();
#include <iostream>
#include <fstream>
int main(void)
{
std::ofstream fileOutput("test.txt");
if (fileOutput.is_open()) {
fileOutput << "hello file stream. \n";
fileOutput.close();
} else
std::cout << "file create error. \n";
return 0;
}
$ ./writedata
$ cat test.txt
hello file stream.
#include <iostream>
#include <fstream>
int main(void)
{
std::ofstream fileOutput("test.txt", std::ios::app);
if (fileOutput.is_open()) {
fileOutput << "append something to the second line. \n";
fileOutput.close();
} else
std::cout << "file create error. \n";
return 0;
}
$ ./writedata
$ cat test.txt
hello file stream.
append something to the second line.
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |