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

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?
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
this dont work either
1
2
3
4
5
string box;
ifstream letterfile ("letters.txt");
getline (letterfile,box);

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

oh, k thanks.
Topic archived. No new replies allowed.