omar shaaban wrote:well the tutorials on the web on this section is too bad what i understand was
first we include the headers
then if we we want to create a new file:
Code: Select all
std::ofstream level;
level.open("newfile.txt");
but if we wanted to open a file
Code: Select all
std::ofstream level("newfile.txt");
and i knew how to add texts and save it by close()
but i have a problem here:
Code: Select all
std::ofstream level("newfile.txt");
int data;
data=level //here is the error
the error is because the 2 are different one is int and the other is ofstream so how can i make data=level(text it have)!!!!?
I don't even understand what you're trying to accomplish with the line data=level... are you trying to get input from the file?
If you're trying to get input you'd use ifstream
for output you'd use ofstream
then you use level as if it were cin or cout.
So if you're trying to get input from the file then you'd go
level << data;
if you're trying to output data, then
level >> data;
BTW theres a second parameter you can set when creating a fsteam, it uses members of the ios namespace, it has things that will create a new file if one doesn't exist, append information, not overwrite, and a few other things.