读书人

istream_iterator有关问题

发布时间: 2012-02-23 22:01:35 作者: rapoo

istream_iterator问题
为什么我的编译不过去?需要include什么东西?谢谢!

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
vector <string> coll;
/*read all words from the standard input
* - source: all strings until end-of-file (or error)
* - destination: coll (inserting)
*/
copy (istream_iterator <string> (cin), //start of source
istream_iterator <string> (), //end of source
back_inserter(coll)); //destination
//sort elements
sort (coll.begin(), coll.end());
/*print all elements without duplicates
* - source: coll
* - destination: standard output (with newline between elements)
*/
unique_copy (coll.begin(), coll.end(), //source
ostream_iterator <string> (cout, "\n "));
//destination
}


下面是报的错。

[cry@localhost C++自己练习]$ g++ -o istream istream.cpp
istream.cpp: In function ‘int main()’:
istream.cpp:13: 错误:‘istream_iterator’ 在此作用域中尚未声明
istream.cpp:13: 错误:expected primary-expression before ‘> ’ token
istream.cpp:14: 错误:expected primary-expression before ‘> ’ token
istream.cpp:14: 错误:expected primary-expression before ‘)’ token
istream.cpp:23: 错误:‘ostream_iterator’ 在此作用域中尚未声明
istream.cpp:23: 错误:expected primary-expression before ‘> ’ token
[cry@localhost C++自己练习]$

[解决办法]
#include <iterator>

读书人网 >C++

热点推荐