2012-07-20 43 views
0

很新的C++和無效的轉換我編譯時出現此錯誤:錯誤:從「無效*」到「炭」 C++陣列

error: invalid conversion from ‘void*’ to ‘char’ 

這究竟是什麼意思?我認爲這是與內存相關的東西,我還沒有啓動陣列或沿着這些線?

這裏是我的代碼:

char students[150][150]; 
int main() 
{ 
    readFile(); 
} 

void readFile() 
{ 
    string line; 
    ifstream file("scores.txt"); 

    for(int i = 0; i < 150; i++) { 
     for (int x = 0; x < 150; x++) { 
      students[i][x] = getline(file, line, ' '); 
     } 
    } 
    for(int i = 0; i < 150; i++) { 
     cout << students[i][i]; 
    } 
} 
+3

指着你http://en.cppreference.com/w/ CPP /串/ basic_string的/函數getline。該行可能是錯誤。 – chris 2012-07-20 21:16:47

+0

非常感謝。愚蠢的錯誤,感謝你的回覆。 – speak 2012-07-20 21:18:18

+1

你想製作一個字符串向量,其中每個索引都是文件的行嗎? – 2012-07-20 21:26:41

回答

4

函數getline返回basic_istream,你不能將其設置爲char類型