Saturday, May 22, 2010

Need help with C++ FSTREAMS!?

This is a very simple code i made to learn how to use fstream:





------------------


#include %26lt;fstream%26gt;


#include %26lt;iostream%26gt;


#include %26lt;cstdlib%26gt;


#include %26lt;string%26gt;


using namespace std;





int main() {


string a;


fstream cra;


cra.open("tape.txt");


if (cra.fail()) cout %26lt;%26lt; "not working" %26lt;%26lt; endl;


cra %26lt;%26lt; "blah blah blah" %26lt;%26lt; endl;


cra %26gt;%26gt; a;


cout %26lt;%26lt; a %26lt;%26lt; endl;


cra.close();


}


------------------





the program inputs the text "blah blah blah" into the file just fine, but it has trouble reading it. I don't really know how to read the file, that's the reason, and the tutorials on various websites haven't helped me.





So can anyone tell me how I can read from the file? Thanks.

Need help with C++ FSTREAMS!?
the problem is that once u write blah blah blah the cursor in the file moves to the end of blah blah blah and after that there is nothing first move cursor to start of file then take input from file it will work.
Reply:Did you try this?


http://www.codersource.net/cpp_file_io.h...


No comments:

Post a Comment