tags:

views:

72

answers:

1

Possible Duplicate:
How do I iterate over cin line by line in C++?

I need to read all lines from a file:

std::ifstream file("...");
std::vector<std::string> svec(
   (std::istream_iterator<std::string>(file)),
   (std::istream_iterator<std::string>()),
);

but it is read as words.

+2  A: 

I believe the issue is that the input methods for std::string will read until a space character is found, then terminate.

Have you tried using std::getline inside a loop?

Check out the C++ FAQ.

Thomas Matthews
Thank you for your reply.I know about std::getline().But the question is more out of curiosity.So, any way can not read the file line by line with iterators?
niXman