相关疑难解决方法(0)

无法将std :: wstring写入wofstream

我在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;
Run Code Online (Sandbox Code Playgroud)

John Smith在行编辑中输入的输出是John Smith10.但对于unicode字符串,什么都没有.

首先我认为这是一个问题QString::toStdWString(),但customersFile << ws.length();写出所有字符串的正确长度.所以我想我在写wstring文件时做错了.[?]

编辑:

我在eclipse中再次写它.并用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 << …
Run Code Online (Sandbox Code Playgroud)

c++ qt4 wstring wofstream

4
推荐指数
1
解决办法
8899
查看次数

标签 统计

c++ ×1

qt4 ×1

wofstream ×1

wstring ×1