看一段代码,有什么问题?进来就有分得哟!

google_chu 2002-11-04 05:34:32
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
vector<string> vs( 100 , string( "Some text" ) ) ;
cout<<vs.size()<<endl;
vector< string > ::iterator it;
int i=0;
for(it=vs.begin();it!=vs.end(); it++){
cout<<*it;//有问题 编译器报ERROR
cout<<it; //如果这样呢结果如下
}
return 0;
}
我只是希望能把里面得字符串挨个的输出来而已
下面得到的全是内存的地址。这是怎么了?哥哥姐姐看看 帮小弟一次咯.
00345350
00345360
00345370
00345380
00345390
003453A0
003453B0
003453C0
003453D0
003453E0
003453F0
00345400
00345410
00345420
00345430
00345440
00345450
00345460
003456B0
003456C0
003456D0
003456E0
003456F0
00345700
00345710
00345720
00345730
00345740
00345750
00345760
00345770
00345780
00345790
003457A0
003457B0
003457C0
003457D0
003457E0
.....

...全文
27 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hotface 2002-12-16
  • 打赏
  • 举报
回复
太难了。
google_chu 2002-11-04
  • 打赏
  • 举报
回复
这地方真不错
这么多高手
厉害。
google_chu 2002-11-04
  • 打赏
  • 举报
回复
谢谢
我明白了,我忘记加一个头文件
#include<string>
真献丑啦,谢谢各位帮忙。
benbenhuhu 2002-11-04
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char* argv[])
{
vector<string> vs( 100 , string( "Some text" ) ) ;
cout<< vs.size()<< endl;
vector< string > ::iterator it;
int i=0;
for(it=vs.begin();it!=vs.end(); it++){
cout<<*it;
}
return 0;
}
cococut 2002-11-04
  • 打赏
  • 举报
回复
在#include <iostream>前面加
#include <string>
因为cout重载的string类型是stl中的!
zhpsam109 2002-11-04
  • 打赏
  • 举报
回复
看看北京万水出的C/C++程序员参考手册,看看迭代器的知识!

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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