2012-10-21 50 views
1

無法迴避這個問題無效轉換 '的std :: basic_ostream <char> :: char_type {又名字符}'

ofstream out; 
out.open("o"); 
string a[5][5]; 
//fill array with letters from 'in.get(ch)'...and then i've tryed: 
//1 
out.put(a[row[0]][col[1]].c_str()); //=>invalid conversion from 'const char*' to 'std::basic_ostream<char>::char_type {aka char}' 
//2: 
out.put(const_cast<char *>(a[row[0]][col[1]].c_str())); //=>invalid conversion from 'char*' to 'std::basic_ostream<char>::char_type {aka char}' 
//3 
char x=const_cast<char *>(a[row[0]][col[1]].c_str()); 
out.put(x); //=>invalid conversion from 'char*' to 'char' 

沒什麼似乎工作。你可以幫我嗎?我該怎麼辦?

回答

4

ofstream::put()用於將單個字符而不是字符串放入流中。

如果你想打印字符串文件流,爲什麼不乾脆用<<

出< <一個[行[0] [COL [1];

+1

哇,thanx。那工作 –

相關問題