我正在尝试使QString以及int的函数。 将QString变量转换为forstream的文件名,然后取整数并将其放入文件中。到目前为止,我已经设法使用一个常量文件名,例如“Filename.dat”,并在其中写入一个变量。然而,当我尝试使用QString这样的:QT ofstream使用变量作为路径名称
void write(const char what,int a){
std::ofstream writefile;
writefile.open("bin\\" + what);
writefile << a;
writefile.close();
}
我得到一个错误
void write(const char,int)': cannot convert argument 1 from 'const char [5]' to 'const char
这是调用写函数();
void Server::on_dial_valueChanged(int value)
{
write("dial.dat",value);
}
当我使用“bin \ dial.dat”而不是将“bin \”与一个字符串结合时,它工作正常。 ofstream.open();使用“const char *”。
我已经尝试了所有的fileTypes所以他们可能不是我的描述
的问题是 - 匹配 没有任何人有一个想法如何结合的“bin \”和为QString,并使其与ofstream的工作? 我花了很多时间搜索它,但仍然无法使它工作。 谢谢! 任何建议,非常欢迎
这' “斌\\” + what'不会做你的事做。这不是字符串连接。 – Logman
那么..在这种情况下,你知道如何连接这两个字符串,并使它们与ofstream一起工作吗?谢谢 –