请教关于c++名字空间的我问题?
小弟现在学c++,遇到一个问题。
我是按照c++ primer 第三版学的。有如下的程序:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
istream_iterator<string> in( cin ), eos;
vector<string> text;
ֵ
copy( in, eos, back_inserter( text ));
sort(text.begin(), text.end());
vector<string>::iterator it;
it = unique( text.begin(), text.end() );
text.erase( it, text.end() );
//show the result
int line_cnt = 1;
for( vector< string >::iterator iter = text.begin(); iter != text.end(); ++iter, ++line_cnt)
{
cout << *iter
<<( line_cnt % 9 ? " " : "\n");
}
cout << endl;
return 0;
}
但是编译的时候总是出现错误,是名字空间的问题。错误在红色一行。
而且书上是没有 using namespace std;此行的。
凡是书上没有名字空间的地方,我编译的时候必须得加上。因此不明白这到底是怎么回事?请教。
我的编译器是gcc 4.2.1。
多谢。