Hey I'm using ifstream to read a file, but I need to read and print all the contents of a file.
for instance:
ifstream inl(filename.c_str());
inl>>stuff;
cout<<stuff<<endl;
Thanks
Hey I'm using ifstream to read a file, but I need to read and print all the contents of a file.
for instance:
ifstream inl(filename.c_str());
inl>>stuff;
cout<<stuff<<endl;
Thanks
Try something like this (look up the correct syntax of getline)
If everythings right this should help you.Code:ifstream file("file"); while(!file.eof()); { file.getline(var,1000); cout<<var; } file.close();
[edit]Whoops, forgot to close the file [/edit]
since getline() removes the terminating char from the istream buffer you may want to use plain old >> to read in one char at a time using R@mon's loop, unless you know the file is less than 1000 char long. If you know getline() is terminated by the terminating char rather than by length consideration, you can add back the terminating char if you want to, but char by char input prevents the need to do that.