Error in Converting Qstring to std::string
-
hi all and this is my code
@{QString names; ofstream mys("e:/mystock.txt"); mys.open("e:/mystock"); names.toStdString(); mys<<names; mys.close();
}
@
when i change "names" variable to string there is no error
but when i change it to qstring and then i want to change it to std string this error will come:no match for 'operator<<' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'QString')
mys<<names;
^Thanks
-
[quote]
@
names.toStdString();
@
[/quote]You need to use the return value of toStdString(). The function returns a copy of your data as a std::string, but it doesn't modify names. names is still a QString. -
You're welcome :)
@
mys << names.toStdString();
@