从'const char *'无效转换为'std :: basic_ostream <char> :: char_type {aka char}'</char>

时间:2012-10-21 10:03:25

标签: c++

无法解决此问题

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'

Nothin似乎在努力。你能帮助我吗?我该怎么办?

1 个答案:

答案 0 :(得分:4)

ofstream::put()用于将单个字符而不是字符串放入流中。

如果要将字符串打印到文件流,为什么不简单地使用<<

out&lt;&lt;一个[行[0]] [COL [1]];