Skip to main content
deleted 2 characters in body
Source Link
FailedDev
  • 27k
  • 9
  • 56
  • 74

This is a classicalclassic example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise. If you use the vector for just getting iterators for the numbers, you can use the istream iterators directly:

istream_iterator<int> begin(lineStream), end; while(begin != end) cout << *begin++ << " "; 

This is a classical example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise. If you use the vector for just getting iterators for the numbers, you can use the istream iterators directly:

istream_iterator<int> begin(lineStream), end; while(begin != end) cout << *begin++ << " "; 

This is a classic example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise. If you use the vector for just getting iterators for the numbers, you can use the istream iterators directly:

istream_iterator<int> begin(lineStream), end; while(begin != end) cout << *begin++ << " "; 
added 244 characters in body
Source Link
Johannes Schaub - litb
  • 509.7k
  • 132
  • 928
  • 1.2k

This is a classical example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise. If you use the vector for just getting iterators for the numbers, you can use the istream iterators directly:

istream_iterator<int> begin(lineStream), end; while(begin != end) cout << *begin++ << " "; 

This is a classical example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise.

This is a classical example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise. If you use the vector for just getting iterators for the numbers, you can use the istream iterators directly:

istream_iterator<int> begin(lineStream), end; while(begin != end) cout << *begin++ << " "; 
Source Link
Johannes Schaub - litb
  • 509.7k
  • 132
  • 928
  • 1.2k

This is a classical example of std::back_inserter.

copy(istream_iterator<int>(lineStream), istream_iterator<int>(), back_inserter(numbers)); 

You can create the vector right from the start on, if you wish

vector<int> numbers((istream_iterator<int>(lineStream)), istream_iterator<int>()); 

Remember to put parentheses around the first argument. The compiler thinks it's a function declaration otherwise.