这个容器存储是string类型,还是*char?怎么用迭代器输出呢?

紫色动力 2010-08-25 10:00:44
程序如下:

#include<iostream>
#include<vector>
#include<algorithm>

using std::vector;
using std::string;
using std::cout;
using std::endl;

int main(void)
{
vector<string> svec1;

svec1.push_back("Good");
svec1.push_back("Hello");
svec1.push_back("World");

vector<string>::iterator it = svec1.begin();
cout<<*it<<endl;//这行出错!!

return 0;
}


这个容器存储的到底是什么类型?怎么用迭代器输出?谢谢!!
...全文
132 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinbaby 2010-08-25
  • 打赏
  • 举报
回复
stl啊
紫色动力 2010-08-25
  • 打赏
  • 举报
回复
低级错误啊,太粗心了,谢谢!!
wyzhao0102 2010-08-25
  • 打赏
  • 举报
回复
漏了
#include<string>
愤怒的泡面 2010-08-25
  • 打赏
  • 举报
回复
#include "stdafx.h"


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using std::vector;
using std::string;
using std::cout;
using std::endl;

int main(void)
{
vector<string> svec1;

svec1.push_back("Good");
svec1.push_back("Hello");
svec1.push_back("World");

vector<string>::iterator it = svec1.begin();
cout << *it << endl;//这行出错!!

system("pause");
return 0;
}

//LZ忽略了string库没有包括上。
Polyglot_g 2010-08-25
  • 打赏
  • 举报
回复
正确,g++.
紫色动力 2010-08-25
  • 打赏
  • 举报
回复
各位,我用的不是VC6,有的是VS2010啊
lovestefanie 2010-08-25
  • 打赏
  • 举报
回复
换个编译器吧
vc6实在是比较落后了
liao05050075 2010-08-25
  • 打赏
  • 举报
回复
你用的VC6吧?
改成

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
vector<string> svec1;
svec1.push_back("Good");
svec1.push_back("Hello");
svec1.push_back("World");
vector<string>::iterator it = svec1.begin();
cout<<*it<<endl;
return 0;
}

就可以了。VC6对标准支持不好。你改用其它编译器就不用改都可以

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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