简体   繁体   中英

invalid conversion from 'const char*' to 'std::basic_ostream<char>::char_type {aka char}'

Can't get around this problem

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 seems to be working. Can you help me? What should i do?

ofstream::put() is for putting individual characters, not strings, to the stream.

If you want to print the string to the file stream, why not simply use << :

out << a[row[0]][col[1]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM