请帮我看一段小程序

startfrom0 2006-01-03 10:07:28
请高手指导我一下
#include <iostream>
#include <list>
#include <string>
using namespace std;
void putValues(const list<string>& str)
{
cout<<"("<<str.size()<<")\n<";
for(int i=0;i<str.size();i++)
{
cout<<str<<endl;
}
cout<<">"<<endl;
}
void main()
{
list<string> str;
str.push_back(string("aaa"));
str.push_back(string("bbb"));
str.push_back(string("ccc"));
putValues(str);
}

编译时有一个错误:
:\C++专区\C++ PRIMER\CHARPTER7\putvalues.cpp(10) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'const class std::list<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
>,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >' (or there is no acceptable conversion)
Error executing cl.exe.
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
khwidesea 2006-01-03
  • 打赏
  • 举报
回复
同意楼上的。
sms88 2006-01-03
  • 打赏
  • 举报
回复
楼上的正解
要用*运算符
cunsh 2006-01-03
  • 打赏
  • 举报
回复
void putValues(const list<string>& str)
{
cout<<"("<<str.size()<<")\n<";
for(list<string>::const_iterator i = str.begin();
i != str.end(); ++i)
{
cout<<*i<<endl;
}
cout<<">"<<endl;
}
fndxm 2006-01-03
  • 打赏
  • 举报
回复
cout<<str<<endl;
你这里的str是一个list,<<没有对list类的的输出操作
startfrom0 2006-01-03
  • 打赏
  • 举报
回复
谢谢各位大力相助,结贴给分

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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