A
arnuld
/* C++ Primer - 4/e
*
* STATEMENT
* write a program to read sequence of strings from the standard
* input into a vector. Print the vector.
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
int main()
{
std::vector<std::string> svec;
std::string word;
while( std::cin >> word )
{
svec.push_back( word );
}
/* print the vector */
std::cout << "\n\n----- You Entered -------\n\n";
std::copy( svec.begin(), svec.end(),
std:stream_iterator<std::string>( std::cout, "\n" ) );
return 0;
}
It runs fine. Is there any way I can replace what while loop with
std::copy ?
*
* STATEMENT
* write a program to read sequence of strings from the standard
* input into a vector. Print the vector.
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
int main()
{
std::vector<std::string> svec;
std::string word;
while( std::cin >> word )
{
svec.push_back( word );
}
/* print the vector */
std::cout << "\n\n----- You Entered -------\n\n";
std::copy( svec.begin(), svec.end(),
std:stream_iterator<std::string>( std::cout, "\n" ) );
return 0;
}
It runs fine. Is there any way I can replace what while loop with
std::copy ?