QStringのファイル入出力について
もっといい方法があるのかもしれないけれど、とりあえずこのパターンでうまくいっているので、メモ。
<<出力>>
ofstream out;
QString txt = "テストです";
out << txt.toLocal8Bit().data() << std::endl;
<<入力>>
char buff[ MAX ];
ifstream in;
int pos = 0;
char c;
in.get( c );
while (( c != '\n' )&&( !in.eof() )){
if ( pos <= MAX ) buff[ pos++ ] = c;
in.get( c );
}
buff[ pos ] = 0;
QString ts="";
if ( buff[ 0 ] != 0 ){
ts = QString::fromLocal8Bit( buff );
}
てな感じ。
| 固定リンク
この記事へのコメントは終了しました。
コメント