vc编译问题??救急!!

hewittlee 2004-05-03 05:08:58
#include <iostream>
#include <vector>
#include <string>
#include <iterator>

int main()
{string words[4]={"dd","kk","aa","jj"};

vector<string> svec(words,words+4);

for(vector<string>::iterator it=svec.begin();it!=svec.end();it++)
cout<<*it<<" ";

cout<<endl;
return 0;
}



编译就出现下列问题:
--------------------Configuration: vec6 - Win32 Release--------------------
Compiling...
vec.cpp
C:\exam\vec6\vec.cpp(4) : error C2065: 'string' : undeclared identifier
C:\exam\vec6\vec.cpp(4) : error C2146: syntax error : missing ';' before identifier 'words'
C:\exam\vec6\vec.cpp(4) : error C2065: 'words' : undeclared identifier
C:\exam\vec6\vec.cpp(4) : error C2109: subscript requires array or pointer type
C:\exam\vec6\vec.cpp(4) : error C2059: syntax error : '{'
C:\exam\vec6\vec.cpp(4) : error C2143: syntax error : missing ';' before '{'
C:\exam\vec6\vec.cpp(4) : error C2143: syntax error : missing ';' before '}'
C:\exam\vec6\vec.cpp(7) : error C2065: 'vector' : undeclared identifier
C:\exam\vec6\vec.cpp(7) : error C2065: 'svec' : undeclared identifier
C:\exam\vec6\vec.cpp(7) : warning C4804: '>' : unsafe use of type 'bool' in operation
C:\exam\vec6\vec.cpp(7) : warning C4552: '>' : operator has no effect; expected operator with side-effect
C:\exam\vec6\vec.cpp(10) : error C2039: 'iterator' : is not a member of '`global namespace''
C:\exam\vec6\vec.cpp(10) : error C2065: 'iterator' : undeclared identifier
C:\exam\vec6\vec.cpp(10) : warning C4804: '>' : unsafe use of type 'bool' in operation
C:\exam\vec6\vec.cpp(10) : error C2146: syntax error : missing ';' before identifier 'it'
C:\exam\vec6\vec.cpp(10) : warning C4552: '>' : operator has no effect; expected operator with side-effect
C:\exam\vec6\vec.cpp(10) : error C2065: 'it' : undeclared identifier
C:\exam\vec6\vec.cpp(10) : error C2228: left of '.begin' must have class/struct/union type
C:\exam\vec6\vec.cpp(10) : error C2228: left of '.end' must have class/struct/union type
C:\exam\vec6\vec.cpp(10) : error C2146: syntax error : missing ')' before identifier 'it'
C:\exam\vec6\vec.cpp(10) : error C2059: syntax error : ';'
C:\exam\vec6\vec.cpp(10) : error C2059: syntax error : ')'
C:\exam\vec6\vec.cpp(11) : error C2146: syntax error : missing ';' before identifier 'cout'
C:\exam\vec6\vec.cpp(11) : error C2065: 'cout' : undeclared identifier
C:\exam\vec6\vec.cpp(11) : error C2100: illegal indirection
C:\exam\vec6\vec.cpp(11) : error C2297: '<<' : illegal, right operand has type 'char [3]'
C:\exam\vec6\vec.cpp(13) : error C2065: 'endl' : undeclared identifier
C:\exam\vec6\vec.cpp(13) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
Error executing cl.exe.

vec.obj - 23 error(s), 5 warning(s)


希望各位高手能帮帮小第!!
...全文
114 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wishare 2004-05-03
  • 打赏
  • 举报
回复
虽然抛弃了,但我们还用
李马 2004-05-03
  • 打赏
  • 举报
回复
建议使用
using namespace std;

.h的方法已经被最新的C++标准抛弃了。
madhappy 2004-05-03
  • 打赏
  • 举报
回复
1 在后面加上 using namespace std;
2 #include <iostream.h>
#include <vector.h>
#include <string.h>
#include <iterator.h>
fenforever 2004-05-03
  • 打赏
  • 举报
回复
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
using namespace std; // ---> 这是很重要的一句

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧