返回   cpper编程论坛 > 技术杂烩
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

技术杂烩 找不到地方的技术问题?这里!

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2002-11-18
ak ak 当前离线
初级会员
 
注册日期: 2002-11-18
帖子: 3
ak 正向着好的方向发展
默认 vc和dev-c++

essential c++中一道题,用dev-c++编译无错,用vc有103个warning.
代码:
#include <iostream> #include <string> #include <fstream> #include <map> using namespace std; int main() { void display(const map<string, int>& ); ifstream in_file("D:\\Source\\text1.txt"); string word; map<string, int> words; while (in_file >> word) { words[word]++; } display(words); return 0; } void display(const map<string, int> &wordmap) { map<string, int>::const_iterator it = wordmap.begin(); for (; it != wordmap.end(); it++) { cout << it->first << "-" << it->second <<" "; } }
essential c++中另一道题的一部分,dev-c++编译无错且运行正常,但vc中有4个warning,且不能正常运行
代码:
#include <iostream> #include <string> #include <vector> #include <fstream> #include <algorithm> using namespace std; bool lessstr(string str1,string str2) { return (str1.size()<=str2.size()); } void display(const vector<string> &vec) { vector<string>::const_iterator it = vec.begin(); for(; it!=vec.end(); it++) { cout<<*it<<"\t"; } return; } int main() { ifstream in_file("D:\\Source\\text2.txt"); vector<string> word; string temp; while (in_file>>temp) { word.push_back(temp); } sort(word.begin(),word.end(),lessstr); display(word); return 0; }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2002-11-18
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,138
文章: 20
polyrandom 正向着好的方向发展
默认

首先,warning你可以仔细看看。很多warning是无所谓的,只是一些信息,你可以disable的。
其次,我没有仔细看你的代码,所以也不知道确切的错误所在。但是你的lessstr肯定是写错了。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2002-11-18
ak ak 当前离线
初级会员
 
注册日期: 2002-11-18
帖子: 3
ak 正向着好的方向发展
默认

我才刚看完essential的泛型程序设计这章,还有好多搞不懂。那个lessstr肯定有问题,我只是不明白为什么dev-c中一切正常,为什么vc中却不能运行。那么正确的lessstr又该怎么写呢?
本人初学者,请多指教!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2002-11-19
polyrandom 的头像
超级版主
 
注册日期: 2002-09-03
帖子: 3,138
文章: 20
polyrandom 正向着好的方向发展
默认

lessstr应该表达的意思是小于,但是你写的是小于等于。逻辑上就错了。
跨编译器跨库,自然会有些不一样,但是一般来说,是你写的代码不好,依赖于特定实现了。最好的方法是调试!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2002-11-19
ak ak 当前离线
初级会员
 
注册日期: 2002-11-18
帖子: 3
ak 正向着好的方向发展
默认

好的,我试试.
多谢了!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 09:54 AM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2009,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0