fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4.  
  5. struct line : std::string
  6. {
  7. friend std::istream & operator >> (std::istream & in, line & ln)
  8. {
  9. return std::getline(in, ln);
  10. }
  11. };
  12.  
  13. int main() {
  14. std::istream_iterator<line> begin(std::cin), end;
  15. std::vector<std::string> allLines(begin, end);
  16.  
  17. std::cout << allLines.size() << " lines read from file, and they're :" << std::endl;
  18. std::copy(allLines.begin(), allLines.end(),
  19. std::ostream_iterator<std::string>(std::cout, "\n"));
  20. return 0;
  21. }
Success #stdin #stdout 0.02s 2820KB
stdin
Would 
@Nawaz's answer 
work on cin.
Yes, and they would.
And here is the prooof :-)
stdout
5 lines read from file, and they're :
Would 
@Nawaz's answer 
work on cin.
Yes, and they would.
And here is the prooof :-)