0

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.

Community
  • 1
  • 1
niXman
  • 1,698
  • 3
  • 16
  • 40
  • 1
    Duplicate of [How do I iterate over cin line by line in C++?](http://stackoverflow.com/questions/1567082/how-do-i-iterate-over-cin-line-by-line-in-c) (Ok, it's not an _exact_ duplicate, but the answers there should all apply to this question as well). – James McNellis May 17 '10 at 16:09

1 Answers1

2

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
  • 56,849
  • 17
  • 98
  • 154
  • 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 May 17 '10 at 19:13