错误 1 error C2678: 二进制“==”: 没有找到接受“std::basic_string<_Elem,_Traits,_Ax>”类型的左操作数的运

贱人的诱惑在唱歌 2012-07-19 08:27:23
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<fstream>
#include<iterator>
using namespace std;
class GreaterThan
{
public:
GreaterThan(int sz=6):_size(sz){}
int size(){return _size;}
bool operator()(const string &s1){return s1.size()>_size;}
private:
unsigned int _size;
};
class PrintElem
{
public:
PrintElem(int lineLen=8):_line_length(lineLen),_cnt(0){}
void operator()(const string &elem)
{
++_cnt;
if(_cnt %_line_length==0){cout<<'\n';}
cout<<elem<<" ";
}
private:
int _line_length;
int _cnt;
};
class LessThan
{
public:
bool operator()(const string& s1,const string& s2){return s1.size()<s2.size();}
};
typedef vector<string> textwords;
void process_vocab(vector<textwords> *pves)
{
if(!pves)
return;错误 1 error C2678: 二进制“==”: 没有找到接受“std::basic_string<_Elem,_Traits,_Ax>”类型的左操作数的运算符(或没有可接受的转换) d:\visual 2010\vc\include\algorithm 148 1 泛型

vector<string> texts;
vector<textwords>::iterator iter;
for(iter=pves->begin();iter!=pves->end();iter++)
{
copy((*iter).begin(),(*iter).end(),back_inserter(texts));
}
sort(texts.begin(),texts.end());
for_each(texts.begin(),texts.end(),PrintElem());
cout<<"\n\n";
vector<string>::iterator it;
it=unique(texts.begin(),texts.end());
texts.erase(it,texts.end());
for_each(texts.begin(),texts.end(),PrintElem());
cout<<"\n\n";
stable_sort(texts.begin(),texts.end(),LessThan());
for_each(texts.begin(),texts.end(),PrintElem());
cout<<"\n\n";
int cnt=0;
cnt=count(texts.begin(),texts.end(),GreaterThan());//计数
cout<<"numbers greater than six "<<cnt<<endl;

static string rw[]={"the","but","and","or","if"};
vector<string> remove_words(rw,rw+5);
vector<string>::iterator its=remove_words.begin();
for(;its!=remove_words.end();its++)
{
int cnt=count(texts.begin(),texts.end(),*its);
cout<<cnt<<" "<<*its<<endl;
texts.erase(remove(texts.begin(),texts.end(),*its),texts.end());
}
for_each(texts.begin(),texts.end(),PrintElem());
cout<<"\n\n";
}
void mian()
{
vector<textwords> sample;
vector<string> t1;
vector<string> t2;
string t1fn,t2fn;
cout<<"text1";
cin>>t1fn;
cout<<"text2";
cin>>t2fn;
ifstream infile1(t1fn.c_str());
ifstream infile2(t2fn.c_str());
istream_iterator<string> input_set1(infile1),eos;
istream_iterator<string> input_set2(infile2);
copy(input_set1,eos,back_inserter(t1));
copy(input_set2,eos,back_inserter(t2));
sample.push_back(t1);
sample.push_back(t2);
process_vocab(&sample);
system("pause");

}
error C2678: 二进制“==”: 没有找到接受“std::basic_string<_Elem,_Traits,_Ax>”类型的左操作数的运算符(或没有可接受的转换)

怎么回事啊
...全文
2827 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
志汉天涯 2013-08-29
  • 打赏
  • 举报
回复
huliang66 2013-08-27
  • 打赏
  • 举报
回复
引用 11 楼 liuzhihan209 的回复:
增加 #include<string>
正确答案
rocktyt 2013-06-04
  • 打赏
  • 举报
回复
count改成count_if mian改成main后编译通过
赵4老师 2013-06-04
  • 打赏
  • 举报
回复
语法糖越甜,编译调试查错越苦!
lm_whales 2013-06-04
  • 打赏
  • 举报
回复
二进制“==”这个是翻译错误。 应该是二元运算符 “==”。 cnt=count(texts.begin(),texts.end(),GreaterThan()); == 没有实现 ==运算符呀!
www_adintr_com 2013-05-30
  • 打赏
  • 举报
回复
main 不是 "void mian()"
志汉天涯 2013-05-30
  • 打赏
  • 举报
回复
增加 #include<string>
mstlq 2012-07-20
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

引用 7 楼 的回复:
C/C++ code
cnt=count(texts.begin(),texts.end(),GreaterThan());//计数

检讨一下上面那句

返回的是计的数啊,没问题啊
[/Quote]
count是靠==来判断是否技术的 换言之,他会执行 string类 == GreaterThan类的操作,楼主没有提供这种重载

看楼主的代码,应该用count_if
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
C/C++ code
cnt=count(texts.begin(),texts.end(),GreaterThan());//计数

检讨一下上面那句
[/Quote]
返回的是计的数啊,没问题啊
mstlq 2012-07-20
  • 打赏
  • 举报
回复
cnt=count(texts.begin(),texts.end(),GreaterThan());//计数

检讨一下上面那句
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
C/C++ code
if(_cnt %_line_length==0){cout<<'\n';}
好好看看这句代码。
[/Quote]

没问题啊,左边操作数都是int型的,哪里不对
  • 打赏
  • 举报
回复
没问题啊,左边操作数都是int型的,哪里不对了?
未注销 2012-07-20
  • 打赏
  • 举报
回复
if(_cnt %_line_length==0){cout<<'\n';}
好好看看这句代码。
  • 打赏
  • 举报
回复
再跪!
  • 打赏
  • 举报
回复
跪求指导!!
  • 打赏
  • 举报
回复
求指导
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
引用 8 楼 的回复:

引用 7 楼 的回复:
C/C++ code
cnt=count(texts.begin(),texts.end(),GreaterThan());//计数

检讨一下上面那句

返回的是计的数啊,没问题啊

count是靠==来判断是否技术的 换言之,他会执行 string类 == GreaterThan类的操作,楼主没有提供这种重载

看楼主的……
[/Quote]
改了,它说必须定义入口点。。
内容概要:本文档为一份《计算机程序设计语言(C++)》课程的实验报告,涵盖了从基础语法到面向对象编程的多个实验内容。实验内容包括基础语法练习(如银行存款计算、数值比较、科学计算)、控制结构(分支与循环,如闰年判断、素数判定、Kaprekar黑洞数)、数组操作(一维与二维数组的排序、查找、极值计算、杨辉三角)、函数定义与应用(递归、参数传递、函数重载)以及面向对象编程(类与对象的设计、继承、多态性、文件操作)。文档详细展示了每个实验的任务描述、具体C++代码实现、测试结果及实验分析,体现了从简单到复杂、逐步深入的学习路径。; 适合人群:具备C++基础语法知识,正在学习或巩固程序设计课程的在校大学生及初级编程学习者。; 使用场景及目标:①作为C++课程的配套实验指导材料,帮助学生通过实践掌握编程基础知识和核心算法;②用于自学练习,提升对循环、数组、函数和面向对象等核心概念的理解与编码能力。; 阅读建议:学习者应结合文档中的代码实例,动手在编程环境中逐一实现并调试,重点关注代码逻辑、边界条件处理和算法效率,通过对比预期输出与实际输出加深对知识点的掌握。

65,210

社区成员

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

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