for example we have created file in c++ how to write content in this file and then output on screen?
+1
A:
Read this and then come back and ask if you have a more specific question, thanks.
Stephen
2010-07-28 11:08:59
i have question no one gave me output why?
2010-07-28 12:47:42
Because the question you asked was a very general and to be honest a quite simple question. While we do not demand you spend hours googling for an answer, for something like this a quick google for "c++ write content file" would get you the link I provided in my answer, which is has both code examples and is also a good tutorial on file reading/writing in C++. vtorhonen below actually quoted the examples from that link, so that you don't even have to click on it. If you are still struggling, I can write up an example in my answer for you.
Stephen
2010-07-28 12:56:09
A:
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.
vtorhonen
2010-07-28 11:10:38