I used the
ofstream fout; //fout is a handle, I think
fout.open("file.txt"); //opens file.txt with the fout handle thing
To output to the file the line is:
fout << "word"; //pretty simple, right?
I've messed around a bit with reading from files too. If I open a file with "ifstream" instead of "ofstream" (ifstream = i-f-stream = input-file-stream) I have the ability to read from the file. I can then input the text to a string. The problem here is that the input line looks like this:
fin >> string; //problem = too simple... how can I specify what to get?
So now we have the text inside of the string, and it reads all the text up to any blank spots (spaces or returns). If I put:
fin >> string;
fin >> string;
It inputs up to the blank spot, then inputs whatever is past the blank spot and overwrites the first thing. Therefore if the file contained "a b" string would contain "b".
That's about as far as I've gotten so far... but I have about a weeks time to make up so there's much more to come!
No comments:
Post a Comment