谁给我个STL实现的简单例子呀

certbuggy 2003-10-28 04:29:53
我在VC++ 6.0+ SP5 下编译候捷的那本《泛型编程于STL》那本书的第一个例子就通不过,到底要包含哪些库呀?怎么设置?
#include <IOSTREAM>
#include <VECTOR>

int main()
{
vector<string> V;
string tmp;

while(getline(cin,tmp))
V.push_back(tmp);

sort(V.begin(),V.end());
copy(V.begin(),V.end(),ostream_iterator<string>(cout,"\n"));

return 0;
}
...全文
35 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
leyt 2003-10-28
  • 打赏
  • 举报
回复
为什么要用C++默认的命名空间呀?
---------------------------------------------------------------------------
因为那些库函数被封装在std的名字空间里。
certbuggy 2003-10-28
  • 打赏
  • 举报
回复
为什么要用C++默认的命名空间呀?另外stl有没有msdn那样比较详细,查找方便的权威文档?
hlnpro 2003-10-28
  • 打赏
  • 举报
回复
你忘了using namespace std 了。

给你一个例子吧:

#include <list>
#include <algorithm>
#include "iostream.h"
using namespace std;

list<int> lint;
for(int i=0;i<100;i++)
lint.push_back(i);

list<int>::iterator ite=lint::begin();
if((ite=find(lint.begin(),lint.end(),33)==lint.end())
cout<<"can't find"<<endl;
else
cout<<"find it"<<endl;

临时写的,你试试看!
certbuggy 2003-10-28
  • 打赏
  • 举报
回复
不行呀,怎么还是一样?
ch_etang 2003-10-28
  • 打赏
  • 举报
回复
#include <IOSTREAM>
#include <VECTOR>
改成小写

#include <string>
#include <algorithm>
certbuggy 2003-10-28
  • 打赏
  • 举报
回复
我的email:codebuggy@hotmail.com

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧