wofstream

How to portably write std::wstring to file?

送分小仙女□ 提交于 2020-02-12 08:57:14
问题 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 decide what encoding to use - let us instead assume that I read this string from a file encoded in e.g. UTF-8] I would very much like to get this into a file reading (when text editor is set to the correct encoding) abcàdëefŸg€hhhhhhhµa but ofstream is

Outputting 'wchar_t*' to an 'ofstream'

孤人 提交于 2020-01-29 06:02:25
问题 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<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

Outputting 'wchar_t*' to an 'ofstream'

空扰寡人 提交于 2020-01-29 06:01:25
问题 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<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

Reading and writing files in Cyrillic in c++

烈酒焚心 提交于 2020-01-02 20:24:44
问题 I have to first read a file in Cyrillic, then randomly pick random number of lines and write modified text to a different file. No problem with Latin letter, but I run into a problem with Cyrillic text, because I get some rubbish. So this is how I tried to do the thing. Say, file input.txt is ааааааа ббббббб ввввввв I have to read it, and put every line into a vector: vector<wstring> inputVector; wstring inputString, result; wifstream inputStream; inputStream.open("input.txt"); while(

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

ぐ巨炮叔叔 提交于 2019-12-28 04:07:10
问题 I wrote the following program using VS2008: #include <fstream> 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 save my source file in unicode, I said "yes, please". Then I run the program, and myfile appeared in my project's folder. I opened it with notepad, the file was empty. I recalled that notepad supported only ASCII data. I opened it with WordPad, it was still

Why does my std::wofstream write ansi?

本秂侑毒 提交于 2019-12-24 13:33:59
问题 I've got wide string and I'm writing it to a wofstream that I opened in out|binary mode. When I look in the resultant file, it's missing every other byte. I was expecting that when I opened the file in visual studio with the binary editor that I'd see every other byte as a zero, but I'm not seeing the zeros. Do you know what I'm missing? Thanks. The code is something like this: CAtlStringW data = L"some data"; wofstream stream("c:\hello.txt", ios_base:out|ios_base:binary); stream.write( data

Issue on writing wstring to a file for hebrew/arabic language

和自甴很熟 提交于 2019-12-22 14:55:52
问题 I want to read hebrew(unicode) using xerces parser. I am able to read the value in XMLCh. However, while writing it to another file I get gargabe value. I tried using ofstream, wofstream but didnot helped. Let me know your suggestions 回答1: The problem with wofstream is that it accepts the wide string for the open() method but does not actually write wide characters to the file. You have to be explicit about that and imbue() it with a locale that has a codecvt with the encoding you want.

Serialization example of boost/archive/binary_woarchive.hpp and/or boost/archive/binary_wiarchive.hpp?

半世苍凉 提交于 2019-12-20 01:46:18
问题 I'm trying to find a good example of how to use these binary wide character versions of boost's serialization stuff. I pieced together some code to try and get it working, but unfortunately I get bombarded with linker errors when trying to compile it. Here's my code, in case I'm doing anything obviously wrong: #include <cstdlib> #include <iostream> #include <fstream> #include <string> #include <vector> #include <boost/archive/binary_woarchive.hpp> #include <boost/archive/binary_wiarchive.hpp>

Reading random access files [closed]

断了今生、忘了曾经 提交于 2019-12-13 04:13:37
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have developed a C++ application for reading and writing data on a random access file. (I use Visual C++ 2010) Here is my program: #include <iostream>

Read/write unicode c++

别等时光非礼了梦想. 提交于 2019-12-12 10:15:46
问题 Sadly this is the third time this week I have to post a question. I have to write text to a file with unicode encoding (or UTF8). This is what I do: creating wofstream mystream; and then I put a wstring in it like this mystream << L"hello world"; First question: what kind of encoding the stream uses in my case? Secondly, I want to load my new file, but how to read the lines? The ifstream 's getline is not working because the line ends up ruined obviously. 回答1: wchar_t , the type that backs