2013-12-14 100 views
0

我需要一種算法將ppm格式的任何彩色圖像轉換爲C++中只有8種顏色。我嘗試此代碼,我一直面臨着一個錯誤與>><<運營商:將任何彩色PPM圖像轉換爲僅有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 
+0

什麼錯誤?你將如何將圖像轉換爲8種顏色? –

+0

我不知道這段代碼是否正確,醫生給了我們這個任務,並告訴我們你可以使用這段代碼,但首先修改它,無論如何,當我寫這段代碼,並達到9-12行,它給了我錯誤(錯誤錯誤C2678:二進制'>>':找不到操作符找到'std :: ifstream'類型的左側操作數(或者沒有可接受的轉換)\t c:\ users \ atiyeh \ documents \ visual studio 2010 \ projects \屁股2 \毫米屁股2 \毫米屁股2.cpp \t 15) – user3101920

+0

這聽起來像你錯過了一些包括。爲什麼不編輯問題來包含整個cpp文件並在格式化方面進行一些工作。你也可以添加任何你遇到的問題。 –

回答

相關問題