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
0
votes
0 answers

std::wofstream gets broken in binary mode in GCC but works in MSVC

The following piece of code produces a file with a single byte when compiled in MSVC, but when compiled by GCC 8.3 it produces an empty file. std::wofstream out("tmpUTF16BrokenBOMFile.txt", std::ios_base::binary); const wchar_t c = 0xFE; // Both…
Ibraim Ganiev
  • 8,934
  • 3
  • 33
  • 52
0
votes
0 answers

Writing with std::string and std::wstring objects to the same file

I would like to know if writing to the same file with std::string and std::wstring objects is safe for sure. I have a snippet like this: void foo(std::string&& msg) { std::ofstream file{ "log.txt", std::ios_base::app }; file << msg <<…
Evelekk
  • 159
  • 7
0
votes
0 answers

C++ Write unicode (wchar_t) char by char to a file results in empty file

So, I need to read a unicode file first, then transform it using Huffman's algorithm (effectively compress it) and write it to a new file. Reason for unicode is special chars like hyphen - the longer dash and other - without unicode, reading and…
dodancs
  • 357
  • 1
  • 5
  • 15
0
votes
0 answers

Why does wofstream output stop at a certain point

I am trying to write into a file wchar_t(s) from value 0 to max (FFFF or 65,535). The process is successful but when I opened the output file it ended at value 256 with no symbol. Why does this happen? I've tried making the program sleep and instead…
0
votes
1 answer

Failing to find a wchar_t that is present in a std::wstring

I was playing with std::wstring and std::wfstream, when I encountered a strange behaviour. Namely, it appears that std::basic_string::find fails to find certain characters. Consider the following code: int main() { std::wifstream…
Fureeish
  • 12,533
  • 4
  • 32
  • 62
0
votes
1 answer

c++ wcout stops outputting, also wofstream stops outputting after some calls

I tried to output contents to a file std::locale::global(std::locale()); std::wofstream file(outfilename , std::wofstream::binary); for (const auto & j : grid[0]) { try { std::wcout << L"String in WideString " <<…
nabz_32x
  • 3
  • 2
0
votes
0 answers

std::wofstream failing to write long long

I have two streams, one to read from and one to write to (diff. files). std::wofstream origin; std::wifstream attach; origin.open(m_SourceFile, std::ios_base::app | std::ios_base::binary); attach.open(csAttachFilename, std::ios_base::in |…
User9123
  • 53
  • 7
0
votes
1 answer

C++ Cannot instantiate codecvt for writing unicode in txt file

Hell0, i need to write a text file (csv file in facts, but nvm) supporting unicode with c++. The source code i have to modify already works great, but only support ANSI. It's working with a wofstream : std::wofstream x; CString stringToWrite; /* …
Spychopat
  • 1
  • 2
0
votes
1 answer

Runtime check failure #2 C/C++

I have encountered a problem in my program that has me somewhat stumped. I had a program that was working fine (it was working fine on VS 2010 this is not an I upgraded to .NET and this error started happening post) with a program that is mostly c…
njvb
  • 1,377
  • 3
  • 18
  • 36
0
votes
1 answer

Type of UTF-16 encoding, using wofstream in Windows

Recently, I want to write a text file in unicode (UTF-16) under Windows. By refering to http://www.codeproject.com/KB/stl/upgradingstlappstounicode.aspx, here is the code I am applying. When I use Notepad to open up the document, here is the…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
0
votes
2 answers

c++ wofstream issue in unicode program

Using unicode compile in vs2008 How do you output many language characters to a file in C++ with wofstream? I can do it in C code no problem e.g. FILE *out; if( (out = _wfopen( L"test.txt", L"wb" )) != NULL ) { fwprintf(out,L"test\r\n"); …
user3725395
  • 145
  • 2
  • 13
0
votes
1 answer

C++ Unresolved external symbol when using wofstream

I am compiling and linking this source code from a batch file and the libraries that I am importing right now are MSVCRT.LIB Kernel32.lib User32.lib The code works until I include string iostream and fstream and create some wofstream objects. That's…
ali
  • 10,927
  • 20
  • 89
  • 138
0
votes
1 answer

Ustring error (during printing)

I want to parse UTF-8 file to ustring, I read this file in str. There is an error: terminate called after throwing an instance of 'Glib::ConvertError'. What should I do? char* cs = (char*) malloc(sizeof(char) * str.length()); strcpy(cs,…
user1635327
0
votes
1 answer

Writing class object to file using streams

I have this code to serialize/deserialize class objects to file, and it seems to work. However, I have two questions. What if instead two wstring's (as I have now) I want to have one wstring and one string member variable in my class? (I think in…
pseudonym_127
  • 357
  • 7
  • 16
0
votes
1 answer

Transactional File Saving in standard C++

Is it possible to implement transactional file saving in standard C++ without using system specific API calls like CopyFile, ReplaceFile, CreateFile etc. Currently I am doing it as follows (using Win32 API specific code): void TransactionalFileSave(…
Thomas Russell
  • 5,870
  • 4
  • 33
  • 68