Questions tagged [wifstream]

std::wifstream is the C++ standard library type for reading wide characters from files.

27 questions
16
votes
3 answers

does (w)ifstream support different encodings

When I read a text file to a wide character string (std::wstring) using an wifstream, does the stream implementation support different encodings - i.e. can it be used to read e.g. ASCII, UTF-8, and UTF-16 files? If not, what would I have to do? (I…
peterchen
  • 40,917
  • 20
  • 104
  • 186
13
votes
1 answer

Why can I not read a UTF-16 file longer than 4094 characters?

Some information: I've only tried this on Linux I've tried both with GCC (7.2.0) and Clang (3.8.1) It requires C++11 or higher to my understanding What happens when I run it I get the expected string "abcd" repeated until it hits the position of…
13
votes
1 answer

Seeking istreambuf_iterator clarifications, reading a complete text file of Unicode characters

In the book “Effective STL” by Scott Meyers, there is a nice example of reading an entire text file into a std::string object: std::string sData; /*** Open the file for reading, binary mode ***/ std::ifstream ifFile (“MyFile.txt”,…
Chris Wiesner
  • 131
  • 1
  • 3
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…
5
votes
1 answer

Why does `getline` on `wifstream` read garbled input from UTF-16 encoded file?

While trying to read a UTF-16 encoded file with hints from this answer, I got the problem that, after reading few thousand characters, the getline-method starts to read in garbage mojibake. Here is my main: #include #include…
5
votes
2 answers

how to use std::wifstream for reading its content as a std::wstring

I am trying this: std::wstringstream wstrStream; std::wifstream wifStream(str.c_str()); wifStream >> wstrStream; but I got this compilation error: error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt…
Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
3
votes
1 answer

How to handle multiple locales for ifstream, cout, etc, in c++

I am trying to read and process multiple files that are in different encoding. I am supposed to only use STL for this. Suppose that we have iso-8859-15 and UTF-8 files. In this SO answer it states: In a nutshell the more interesting part for…
BugShotGG
  • 5,008
  • 8
  • 47
  • 63
2
votes
2 answers

How can I get C++ wfstream to work with Unicode filepath?

I have an application that is working with file I/O using utf-8 encoded widestrings. Working Code: const wchar_t* wc = L"C:\Documents\TestPath\TestFile.txt"; std::wfstream wf(wc); wf.imbue(std::locale(wf.getloc(), new std::codecvt_utf8
2
votes
2 answers

seekg and imbue in wifstream work wrong

I have a file like below: $ xxd 1line 0000000: 3939 ba2f 6f20 6f66 0d0a 99./o of.. I would like to read this one line in C++: #include #include #include #include #include int…
mkk
  • 675
  • 6
  • 17
2
votes
1 answer

How to convert between shared_ptr to FILE* in C++?

I am trying to use a FILE pointer multiple times through out my application for this I though I create a function and pass the pointer through that. Basically I have this bit of code FILE* fp; _wfopen_s (&fp, L"ftest.txt", L"r"); …
Hossein
  • 24,202
  • 35
  • 119
  • 224
1
vote
2 answers

Reading and writing files in Cyrillic in c++

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…
Sergei G
  • 1,550
  • 3
  • 24
  • 44
1
vote
0 answers

How to write a random access iterator for std::wifstream?

My normal procedure is as follows: . . . // I create a wifstream from file std::wifstream wif(L"..."); // Generate a wstring based on file content std::wstring m_wstr((istreambuf_iterator(wif)), istreambuf_iterator()); // Do…
Okan Barut
  • 279
  • 1
  • 7
1
vote
0 answers

How can I read a text file containing Unicode, into a wchar_t pointer using wifstream?

I'm trying to read Unicode characters from a text file into a wchar_t pointer array, using wifstream. Here is a code snippet: locale::global(std::locale("en_US.UTF-8")); std::wifstream inputFile("gsmCharacterSet.txt", std::ifstream::binary |…
yogur
  • 810
  • 10
  • 19
1
vote
0 answers

Cannot open .mtl file unless path is hard coded

I'm having trouble with my .OBJ file model loader. I am reading in the model fine, but when it comes to reading in the .mtl file the file will only open if I hard code the path. I have check the path being given, and it matches the path I hard…
user3640122
  • 15
  • 1
  • 6
1
vote
0 answers

wifstream with imbue, locale produces valgrind errors

I implemented a language detector using ngrams and all works fine so far. In order to detect a bunch of languages I have a set of language dependent ngrams files for each supported language my detector needs to read in before the actual detection is…
Andreas W. Wylach
  • 723
  • 2
  • 10
  • 31
1
2