why does cout give me 0 and not the contents of the file?

devonrevenge (668)
1
2
ifstream letterfile ("letters.txt");
cout << letterfile;


theres a file filled with stuff but i just gets a 0 instead.
my plan is to initialize lots of 2d arrays with a text file, any suggestions?

i was just gonna intitialize a string from the text file and use the string to manage data instead of opening and closing the file all the time, is there a more elegant way?
Moschops (5959)
letterfile is an object of type ifstream. It is NOT the contents of a file.

You can use an ifstream object to read some data from a file into a variable, and then you can output that variable.
Last edited on
devonrevenge (668)
this dont work either
1
2
3
4
5
string box;
ifstream letterfile ("letters.txt");
getline (letterfile,box);

cout<<box;
Moschops (5959)
It does for me. If I had to guess, the file letters.txt is not in the working directory of the executable being run.

devonrevenge (668)
oh, k thanks.
Registered users can post here. Sign in or register to post.