在QT中error invalid operands to binary expression basic_ostreamchar stdchar_traitschar and QString
该错误提示意味着您在使用二元表达式时,使用了不兼容的类型。在这种情况下,您正在尝试将一个std::ostream对象与一个QString对象结合使用,而这两个对象不兼容。
要解决此问题,您需要选择一种类型并将其转换为另一种类型。例如,您可以将QString对象转换为std::string对象,然后使用std::ostream对象输出它。或者,您可以使用QT的QTextStream对象来处理QString对象的输出。
以下是一些可能有用的代码示例:
// 将QString对象转换为std::string对象,并使用std::ostream对象输出它
std::string str = qstr.toStdString();
std::cout << str << std::endl;
// 使用QTextStream对象输出QString对象
QTextStream out(stdout);
out << qstr << endl;
请注意,在使用QTextStream对象时,您需要使用QT的头文件。
原文地址: https://www.cveoy.top/t/topic/fdJm 著作权归作者所有。请勿转载和采集!