"mark" <ma*********@yahoo.com> wrote in message
news:5e**************************@posting.google.c om...
The problem with this code snippet is that only outputs the first word
in the file "test". The file has atleast one line with 4 words in it,
only one word is output. I have tried increasing the array size as
well, still only the first word is output ?
what is the error ?
file "test" contains "Line one here"
output ---> "line"
char str[20];
ifstream b_file("test");
b_file>>str;
cout<<str;
b_file.close();
That is what it is supposed to do. To handle it line-by-line, look up
std::getline(). For instance, the following would open a file and list it,
line-by-line:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream is("somefile.txt");
std::string str;
while (std::getline(is, str)) {
std::cout << str << '\n';
}
}
Regards,
Sumit.