LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 848|回复: 4

使用STL编程的问题

[复制链接]
发表于 2006-10-14 14:39:54 | 显示全部楼层 |阅读模式
从精华区的帖子里拿来学习的,源程序如下:
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main () {
  list<int> Scores;

  Scores.push_back(100); Scores.push_back(80);
  Scores.push_back(45); Scores.push_back(75);
  Scores.push_back(99); Scores.push_back(100);

  int NumberOf100Scores(0);     
  count (Scores.begin(), Scores.end(), 100, NumberOf100Scores);

  cout << "There were " << NumberOf100Scores << " scores of 100" << endl;

  return 0;
}

编译出现的错误如下:

spirit@freefly:~/program$ g++ stlTest.cpp -o stlTest
stlTest.cpp: In function ‘int main()’:
stlTest.cpp:14: 错误: 对 ‘count(std::_List_iterator<int>, std::_List_iterator<int>, int, int&)’ 的调用没有匹配的函数

请问大家这是怎么回事?好像调用STL里的函数没有成功,谢谢大家帮助解决!^_^
发表于 2006-10-14 15:03:16 | 显示全部楼层
int NumberOf100Scores(0)=count (Scores.begin(), Scores.end(), 100);

the form you were using is obsolete and removed from stl
Post by spirit_cg
从精华区的帖子里拿来学习的,源程序如下:
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main () {
  list<int> Scores;

  Scores.push_back(100); Scores.push_back(80);
  Scores.push_back(45); Scores.push_back(75);
  Scores.push_back(99); Scores.push_back(100);

  int NumberOf100Scores(0);     
  count (Scores.begin(), Scores.end(), 100, NumberOf100Scores);

  cout << "There were " << NumberOf100Scores << " scores of 100" << endl;

  return 0;
}

编译出现的错误如下:

spirit@freefly:~/program$ g++ stlTest.cpp -o stlTest
stlTest.cpp: In function ‘int main()’:
stlTest.cpp:14: 错误: 对 ‘count(std::_List_iterator<int>, std::_List_iterator<int>, int, int&)’ 的调用没有匹配的函数

请问大家这是怎么回事?好像调用STL里的函数没有成功,谢谢大家帮助解决!^_^
回复 支持 反对

使用道具 举报

发表于 2006-10-14 15:04:15 | 显示全部楼层
int NumberOf100Scores=count (Scores.begin(), Scores.end(), 100);
回复 支持 反对

使用道具 举报

发表于 2006-10-14 15:14:38 | 显示全部楼层
晚了。按楼上的吧。。。

STL函数用法请查阅 《The C++ Standard Library》。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-14 15:18:31 | 显示全部楼层
我是ÎÙÌ:
http://www.linuxsir.cn/bbs/showthread.php?t=44097
就是¾华帖Ì找到的,呵呵,也¸öô长了,我的一本《C++  Primer》第四版借给同学看了,我只好临时在这里找资料看看。

谢谢楼上的两位,目前的问题解决了。十分感谢! ^_^
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表