Linux システムで Qt/C++ を使用しています。QLineEdit
のテキストをに変換してstd::wstring
に書き込む必要がありstd::wofstream
ます。ASCII 文字列では正しく機能しますが、他の文字 (アラビア語またはウズベク語) を入力すると、ファイルに何も書き込まれません。(ファイルのサイズは 0 バイトです)。
これは私のコードです:
wofstream customersFile;
customersFile.open("./customers.txt");
std::wstring ws = lne_address_customer->text().toStdWString();
customersFile << ws << ws.length() << std::endl;
John Smith
行編集で入力された出力は ですJohn Smith10
。しかし、Unicode 文字列の場合は何もありません。
最初は の問題だと思いましたが、QString::toStdWString()
すべてcustomersFile << ws.length();
の文字列の正しい長さを書き込みます。したがって、ファイルへの書き込みに何か問題があると思いwstring
ます。[?]
編集:
日食でまた書きます。g++4.5でコンパイルしました。結果は同じです:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout << "" << endl; // prints
wstring ws = L"سلام"; // this is an Arabic "Hello"
wofstream wf("new.txt");
if (!wf.bad())
wf << ws;
else
cerr << "some problem";
return 0;
}