Questions tagged [wofstream]

The C++ standard library type std::wofstream is a specialized std::wostream which uses a std::wfilebuf to write wide chars or wide strings to a file.

This is C++ std file output stream for data which has wide characters.

70 questions
24
votes
9 answers

How to portably write std::wstring to file?

I have a wstring declared as such: // random wstring std::wstring str = L"abcàdëefŸg€hhhhhhhµa"; The literal would be UTF-8 encoded, because my source file is. [EDIT: According to Mark Ransom this is not necessarily the case, the compiler will…
user1481860
19
votes
5 answers

Why does wide file-stream in C++ narrow written data by default?

Honestly, I just don't get the following design decision in C++ Standard library. When writing wide characters to a file, the wofstream converts wchar_t into char characters: #include #include int main() { using namespace…
Khaled Alshaya
  • 94,250
  • 39
  • 176
  • 234
19
votes
2 answers

Outputting 'wchar_t*' to an 'ofstream'

I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<
Aan
  • 12,247
  • 36
  • 89
  • 150
16
votes
3 answers

Wrote to a file using std::wofstream. The file remained empty

I wrote the following program using VS2008: #include int main() { std::wofstream fout("myfile"); fout << L"Հայաստան Россия Österreich Ελλάδα भारत" << std::endl; } When I tried to compile it the IDE asked me whether I wanted to…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
14
votes
4 answers

Windows Unicode C++ Stream Output Failure

I am currently writing an application which requires me to call GetWindowText on arbitrary windows and store that data to a file for later processing. Long story short, I noticed that my tool was failing on Battlefield 3, and I narrowed the problem…
RaptorFactor
  • 2,810
  • 1
  • 29
  • 36
7
votes
5 answers

How to write a non-English string to a file and read from that file with C++?

I want to write a std::wstring onto a file and need to read that content as std:wstring. This is happening as expected when the string as L"". But the problem is happening when we have character like Bengali, Kannada, Japanese…
6
votes
2 answers

Boost C++ cross-platform (Windows & Mac) serialization of std::wstring

I am implementing serialization using Boost C++ libraries in a program that is built for Windows (using Visual Studio 2008) and Mac (using GCC). The program uses wide strings (std::wstring) in about 30 of its classes. Depending on the platform,…
Tymek
  • 664
  • 7
  • 8
6
votes
6 answers

C++ unicode questions

I'm aware of ICU and small libraries like the utf8 one on code project (forget the exact name) however none of these are exactly what I want. What I really want is something like ICU but wrapped up in a more friendly manner. Specifically: Fully…
Fire Lancer
  • 29,364
  • 31
  • 116
  • 182
6
votes
1 answer

Unable to write a std::wstring into wofstream

I'm using Qt/C++ on a Linux system. I need to convert a QLineEdit's text to std::wstring and write it into a std::wofstream. It works correctly for ascii strings, but when I enter any other character (Arabic or Uzbek) there is nothing written in the…
sorush-r
  • 10,490
  • 17
  • 89
  • 173
5
votes
2 answers

outputing multibyte string in C++

I have a problem with multibyte char strings. I have simplified my problem as below: std::wstring str = L"multıbyte test string"; std::wofstream f; f.open("F:\\dump.txt"); f << str; f.close(); and the dump file's content is : "mult" Why does it…
xyzt
  • 1,201
  • 4
  • 18
  • 44
5
votes
1 answer

std::wostream_iterator

Why there are no std::wostream_iterator in C++? Is there any good reason for this? #include #include #include #include int main() { std::vector myvec = { L"first", L"second" }; …
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
5
votes
2 answers

How to read a UCS-2 file?

I'm writing a program to get the infomation in *.rc file encoding in UCS-2 Little Endian. int _tmain(int argc, _TCHAR* argv[]) { wstring csvLine(wstring sLine); wifstream fin("en.rc"); wofstream fout("table.csv"); wofstream…
goss.beta
  • 103
  • 2
  • 7
5
votes
2 answers

wostream fails to output wstring

I am using Visual Studio C++ 2008 (Express). When I run the below code, the wostream (both std::wcout, and std::wfstream) stops outputting at the first non-ASCII character (in this case Chinese) encountered. Plain ASCII characters print fine.…
Nathan
  • 10,593
  • 10
  • 63
  • 87
4
votes
2 answers

writing unicode characters/string to file

I'm trying to write unicode characters to file with std::wofstream but the put or write function doesn't write any characters. Sample code: #include #include int main() { std::wofstream file; file.open("output.txt",…
user11157650
4
votes
2 answers

How to write a wstring line contains different language to a file?

I got seperated parts from 22 files in different languages and made them a wstring line like: wstring wstr_line = L"\"IDS_TOAST_ECOON\",\"eco Mode is turned On.\",\"ecoモードをオンにしました。\",\"Režim eco je zapnutý.\",\"Økoindstillingen er aktiveret\"..." I…
goss.beta
  • 103
  • 2
  • 7
1
2 3 4 5