关于vector的
程序如下:
#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::streamsize;
int main()
{
cout<<"please input a sentence: ";
vector<string> sentence;
string x;
while(cin>>x && x!="." )
sentence.push_back(x);
//int num=sentence.size();
typedef vector<string>::size_type vec_sz;
vec_sz size=sentence.size();
int num=size;
cout<<num<<endl;
return 0;
}
老是报错:
Cpp2.cpp
G:\TurboCpp\cppex\cpp2\Cpp2.cpp(22) : error C2653: '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<c
har> > > >' : is not a class or namespace name
G:\TurboCpp\cppex\cpp2\Cpp2.cpp(22) : error C2146: syntax error : missing ';' before identifier 'vec_sz'
G:\TurboCpp\cppex\cpp2\Cpp2.cpp(22) : error C2065: 'vec_sz' : undeclared identifier
G:\TurboCpp\cppex\cpp2\Cpp2.cpp(23) : error C2146: syntax error : missing ';' before identifier 'size'
G:\TurboCpp\cppex\cpp2\Cpp2.cpp(23) : error C2065: 'size' : undeclared identifier
Error executing cl.exe.
Cpp2.exe - 5 error(s), 0 warning(s)
不知道以下三句有什么不对
typedef vector<string>::size_type vec_sz;
vec_sz size=sentence.size();
int num=size;
若换成
//int num=sentence.size();
就能成功
谁知道是怎么回事?还有就是用这三句有什么意义?
刚学c++,希望讲的具体点