Open file with ostream with file name from QFile?
-
I want to output some text by using C++'s ostream but it appears that QFile::fileName() mangles the text string. Is there a way to open a file through ofstream through the string provided by QFile::fileName()?
-
Hi,
Mayby you can use "qtextstream":http://doc.qt.nokia.com/4.7/qtextstream.html or "qdatastream":http://doc.qt.nokia.com/4.7/qdatastream.html ?As for your question. Its possible to pass qfile::filename() to the open call from ofstream.
You only have to add .toascii or .tolatin1 to it.
Like:
@
ofstream ofstr;
QFile f("path_to_file");
fstr.open(f.fileName().toAscii());
@ -
vinb: You usually want to use "toLocal8Bit()" for conversions like that. Both toAscii and even toLatin1 do not work well when a user has non-Latin characters in his file names.
-
thanks for correcting me, Tobias Hunger. :)