| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1766 人关注过本帖
标题:排序字符串大家来看看
只看楼主 加入收藏
三少爷
Rank: 1
等 级:新手上路
帖 子:192
专家分:0
注 册:2004-4-29
收藏
 问题点数:0 回复次数:6 
排序字符串大家来看看

//這是一個升序排序字符串的程序,有点问题,不能正常运行,大家帮忙看看 #include <iostream> #include <algorithm> #include <vector> using namespace std; typedef vector<string> Strings; typedef Strings::iterator Sit; void load(Strings&); void print(Strings);

int main() { Strings v; load(v); sort(v.begin(),v.end()); print(v); return 0; }

void load(Strings& v) { v.push_back("Japan"); v.push_back("Italy"); v.push_back("Spain"); v.push_back("Egypt"); v.push_back("Chile"); v.push_back("Zaire"); v.push_back("Nepal"); v.push_back("Kenya"); }

void print(Strings v) { for(Sit it=v.begin();it!=v.end();it++) cout<<*it<<endl; cout<<endl; }

[此贴子已经被作者于2004-06-19 20:46:47编辑过]

搜索更多相关主题的帖子: 字符 
2004-06-19 20:44
jellen
Rank: 1
等 级:新手上路
威 望:1
帖 子:107
专家分:0
注 册:2004-5-3
收藏
得分:0 
不知楼主运行出现什么错误?我在WinXP + Dev-C++中编译通过,运行也没有问题。
在Borland C++ Compiler 5.5中也通过:)

再见,理想!
2004-06-19 21:07
三少爷
Rank: 1
等 级:新手上路
帖 子:192
专家分:0
注 册:2004-4-29
收藏
得分:0 

我用我的VC++6.0运行后出现如下提示:

--------------------Configuration: sort() in vector - Win32 Debug-------------------- Compiling... sort() in vector.cpp c:\windows\desktop\sort() in vector.cpp(17) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<c har,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information c:\windows\desktop\sort() in vector.cpp(17) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,st d::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information c:\windows\desktop\sort() in vector.cpp(34) : 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 acceptabl e conversion) Error executing cl.exe.

sort() in vector.obj - 1 error(s), 2 warning(s)


2004-06-20 21:58
三少爷
Rank: 1
等 级:新手上路
帖 子:192
专家分:0
注 册:2004-4-29
收藏
得分:0 

提示好像是这个 cout<<*it<<endl; 有问题

但我无法想象撇除这种表达语法以外的一些方式

对编译器的提示也不知所以。


2004-06-20 22:08
zff_ff
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2004-5-12
收藏
得分:0 

cout<<*it<<endl;

应该没问题

v.push_back("Japan"); v.push_back("Italy"); v.push_back("Spain"); v.push_back("Egypt"); v.push_back("Chile"); v.push_back("Zaire"); v.push_back("Nepal"); v.push_back("Kenya");

这些是不是stl

vc6不支持stl


偶是一只想要飞却忘了咋飞的菜鸟
2004-06-20 22:25
onicuka
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2004-6-23
收藏
得分:0 
在最上面加#include &lt;STRING&gt;就可以了.

2004-06-23 09:54
三少爷
Rank: 1
等 级:新手上路
帖 子:192
专家分:0
注 册:2004-4-29
收藏
得分:0 

在提示里面我看不出缺乏这个头文件的征兆

还是有点缺乏经验啊

多谢大家了,最终终于解决了这个问题,虽然不尽完美,还有5个warnings,

但已经无碍大局了。

尤其是要多谢onicuka,

这里细心热心高手真是不少!


2004-06-25 17:13
快速回复:排序字符串大家来看看
数据加载中...
 
   



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

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