【发布时间】:2013-03-14 16:43:57
【问题描述】:
如果没有cout,程序将正确运行; 为什么? 输出缓存有问题?
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
class fn
{
public:
int i;
bool operator()(int,int)
{
++i;
cout<<"what the poodles?\n";
}
};
int main()
{
vector<int> temp(9,9);
vector<int> tmp(2,3);
fn f;
vector<int>::iterator ite;
ite=find_first_of(temp.begin(),temp.end(),tmp.begin(),tmp.end(),f);
if(ite==temp.end())cout<<"Pomeranians!\n";
//cout<<"compared "<<f.i<<" time(s)\n";//if note this ,you'll get defferent output.
return 0;
}
【问题讨论】:
-
代码中的脏话有什么原因吗?
-
你有一个返回布尔值的函子,没有返回语句。
-
你应该认为编译器警告和错误一样糟糕 :) 它们比错误更令人沮丧。
标签: c++ function-object