2012-07-20 40 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类型