error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion

简单程序

#include <iostream.h>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

PrintIt (string& StringToPrint) {
 std::cout<<StringToPrint<<endl;
//; cout<<"asdfds"<<endl;
}

int main (void) {
  list<string> FruitAndVegetables;
  FruitAndVegetables.push_back("carrot");
  
  for_each  (FruitAndVegetables.begin(), FruitAndVegetables.end(), PrintIt);
}
 

如果 #include <iostream.h> 则有错误,
错误如题所示:

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)

把其中的 “.h”去掉,则错误消失,能够正常运行!

你可能感兴趣的:(Algorithm,c,String,list,each)