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;
}