"Wodzu" <br************@wp.pl> wrote in message
news:bq**********@opal.futuro.pl...
Hello there friends...
Can someone show me how to write some text to file and then read it from
that file?
Judging from the nature of your question, I'd really rather
show you some beginner's C++ texts (see
www.accu.org book reviews),
but what the heck:
/* (error checking omitted for brevity) */
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::string data_out("some text");
std::string data_in;
/* write text to a file */
std::ofstream out("file.txt");
out << data_out << '\n';
out.clear();
out.close();
/* read text from file written above */
std::ifstream inp("file.txt");
std::getline(inp, data_in);
if(data_out != data_in)
std::cerr << "Something went wrong\n";
return 0;
}
-Mike