出错,不知道怎么处理

nothing09 2009-03-10 12:30:32
出错,不知道怎么处理
#include "stdafx.h"
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

void doPrint(string & s)
{
cout<<s<<" "<<endl;
}

int main(int argc, char* argv[])
{
deque<string> coll;
coll.assign (3, string("string"));
coll.push_back ("last string");
coll.push_front ("first string");

for_each(coll.begin(), coll.end(), doPrint);

return 0;
}

这个也出错,不知道怎么处理,是不是string不能打印啊?
#include "stdafx.h"
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

void doPrint(string & s)
{
cout<<s<<" "<<endl;
}

int main(int argc, char* argv[])
{
deque<string> coll;
coll.assign (3, string("string"));
coll.push_back ("last string");
coll.push_front ("first string");

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

return 0;
}
...全文
54 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
topwork 2009-03-10
  • 打赏
  • 举报
回复
第一个改成这样:


#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

void doPrint(string & s)
{
cout <<s.c_str() <<" " <<endl;
}

int main(int argc, char* argv[])
{
deque <string> coll;
coll.assign (3, string("string"));
coll.push_back ("last string");
coll.push_front ("first string");

for_each(coll.begin(), coll.end(), doPrint);

return 0;
}
arong1234 2009-03-10
  • 打赏
  • 举报
回复
什么错也不帖出来,别人要看你错误还要在编译器编译下
topwork 2009-03-10
  • 打赏
  • 举报
回复
根本错误是,你上下的代码都没有加

#include <string>

加上这个就好了。

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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