VC中的vector<int>::size_type;}
#include<iostream>
#include<vector>
void main()
{using namespace std;
vector<int>::size_type;}这样子编译没问题,但是
#include<iostream>
#include<vector>
void main()
{using std::vector;
vector<int>::size_type;}就错误了,其实就是USING声明换了,第一个声明是我刚刚在网上查的,第二个是书上说的,不知道为什么?
C:\Documents and Settings\Administrator\Cpp2.cpp(11) : error C2653: 'vector<int,class std::allocator<int> >' : is not a class or namespace name
C:\Documents and Settings\Administrator\Cpp2.cpp(11) : error C2065: 'size_type' : undeclared identifier
新手上入,求指导。。。
是啊。。那本书是C++PRIMER应该不会错。。我觉得是我弄错了,你用的是什么编译器?
还有顺便问下:输出定义了vector<string> text;时为什么会错,如下:
void main()
{
using std::vector;
using std::cin;
using std::endl;
using std::cout;
using std::string;
vector<string> text;
string word;
while(cin>>word)
text.push_back(word);
cout<<text<<endl;
}包含文件就不写了
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
>,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >' (or there is no acceptable conversion)
你用的什么编凯氏译器?在VS2010上简滑,我用两种方式都成功了。
关于你补充的问题。是由于cout的<<操作符无法输出vector<string>类型的变量。
想要输出,只能遍历容器中的内容。
for (vector<string>::const_iterator beg = text.begin();beg != text.end();++beg)
{
cout<盯咐散<*beg<<endl;
}
using std::vector;这种使用方法没错的。我试过了,除了一个警告,没有error。