标题:stl 中的vector
只看楼主
赤冰
Rank: 1
等 级:新手上路
帖 子:397
专家分:0
注 册:2007-1-22
 问题点数:0 回复次数:2 
stl 中的vector

#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
vector<char> chs;
chs.push_back('d');
chs.push_back('a');
chs.push_back('c');
chs.push_back('u');
vector<char>::iterator chIt=chs.begin();

while(chIt!=chs.end())
{
cout<<chIt++;
}
return 0;
}

请问我的这个输出为什么是
dacu??1acu??1cu??1u??1Press any key to continue

而不是 dacu呢

搜索更多相关主题的帖子: vector stl 
2007-08-02 08:28
Arcticanimal
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:341
专家分:20
注 册:2007-3-17
得分:0 
while(chIt!=chs.end())
{
cout<<chIt++;// vector<char>::iterator chIt=chs.begin(); chIt就相当于 char* chIt = &chs.begin();
}
输出的时候就是输出字符串了
这样才是你想要的结果:
while(chIt!=chs.end())
{
cout<<*(chIt++);
}

try new catch
2007-08-02 08:59
赤冰
Rank: 1
等 级:新手上路
帖 子:397
专家分:0
注 册:2007-1-22
得分:0 
谢谢,如果我要是在反向输出呢
2007-08-02 09:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-159808-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.449746 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved