for example we have created file in c++ how to write 开发者_开发问答content in this file and then output on screen?
Read this and then come back and ask if you have a more specific question, thanks.
Taken from here.
Writing:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Reading:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile("example.txt");
while(getline(myfile,line)) {
cout << line << endl;
}
myfile.close();
return 0;
}
You should really use Google.
精彩评论