我需要一种算法,将ppm格式的任何彩色图像转换为C ++中的8种颜色。我尝试了这段代码,但我在>>
和<<
运算符时遇到了错误:
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream in;
in.open("football.ppm");
ofstream out("football8color.ppm");
string header;
int cols, rows,colors;
int r, g, b;
in >> header >> cols >> rows >> colors;
out << header << endl;
out<< cols<< " " << rows <<endl;
out<< colors<< endl;
for ( int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++){
in>> r >> g >> b;
}
out <<endl;
}
in.close();
out.close();
return 0 ;
}
我收到这些错误:
4 IntelliSense: no operator "<<" matches these operands c:\users\atiyeh\documents\visual studio 2010\projects\mm ass 2\mm ass 2\mm ass 2.cpp 18
3 IntelliSense: no operator ">>" matches these operands c:\users\atiyeh\documents\visual studio 2010\projects\mm ass 2\mm ass 2\mm ass 2.cpp 17
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\atiyeh\documents\visual studio 2010\projects\mm ass 2\mm ass 2\mm ass 2.cpp 16
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion) c:\users\atiyeh\documents\visual studio 2010\projects\mm ass 2\mm ass 2\mm ass 2.cpp 15