| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1062 人关注过本帖
标题:STL怎么用啊
只看楼主 加入收藏
赤冰
Rank: 1
等 级:新手上路
帖 子:397
专家分:0
注 册:2007-1-22
收藏
 问题点数:0 回复次数:6 
STL怎么用啊

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
vector<int>str;
str.push_back(3);
str.push_back(3);
str.push_back(2);
str.push_back(7);
sort(str.begin(),str.end());
vector<string>::iterator it;
for(it=str.begin();it!=str.end();it++)
{
cout<<*it;
}
return 0;

}

谁知道我的有什么错误啊调试不过,这个怎么输出阿

搜索更多相关主题的帖子: STL 
2007-08-02 14:10
medicihophy
Rank: 1
等 级:新手上路
威 望:1
帖 子:102
专家分:0
注 册:2007-7-28
收藏
得分:0 
以下是引用赤冰在2007-8-2 14:10:37的发言:

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
vector<int>str;
str.push_back(3);
str.push_back(3);
str.push_back(2);
str.push_back(7);
sort(str.begin(),str.end());
vector<string>::iterator it;//this what?string?should it be int?
for(it=str.begin();it!=str.end();it++)
{
cout<<*it;
}
return 0;

}

谁知道我的有什么错误啊调试不过,这个怎么输出阿


2007-08-02 16:46
赤冰
Rank: 1
等 级:新手上路
帖 子:397
专家分:0
注 册:2007-1-22
收藏
得分:0 

对不起,这样

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
vector<string>str;
str.push_back("aaa");
str.push_back("bbb");
str.push_back("wrer");
str.push_back("asldf");
sort(str.begin(),str.end());
vector<string>::iterator it;
for(it=str.begin();it!=str.end();it++)
{
//这里怎样输出阿
}
return 0;
}

2007-08-02 22:14
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
就你一开始那样输出啊。对迭带器解引用。

Fight  to win  or  die...
2007-08-03 17:55
antter
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-8-27
收藏
得分:0 
就像你写的
cout<<(*it);

PS:
拜2楼的Chinese English - this what?
2007-08-03 18:48
赤冰
Rank: 1
等 级:新手上路
帖 子:397
专家分:0
注 册:2007-1-22
收藏
得分:0 

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
vector<string>str;
str.push_back("aaa");
str.push_back("bbb");
str.push_back("wrer");
str.push_back("asldf");
sort(str.begin(),str.end());
vector<string>::iterator it;
for(it=str.begin();it!=str.end();it++)
{
cout<<(*it);
}
return 0;
}

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

可是它抱错啊像上面

[此贴子已经被作者于2007-8-3 21:43:21编辑过]

2007-08-03 21:42
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
编译器问题吧,你把头文件加上<string>
代码没有任何问题。

Fight  to win  or  die...
2007-08-03 23:21
快速回复:STL怎么用啊
数据加载中...
 
   



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

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