Questions tagged [codecvt]

48 questions
3
votes
1 answer

Is codecvt not supported by Clang or GCC?

I can't even get the basic codecvt example from cppreference.com to compile on GCC 4.9 or Clang 3.4, e.g.: http://goo.gl/HZ5GLH http://coliru.stacked-crooked.com/a/345d6d89949ac1e6
Chris_F
  • 4,991
  • 5
  • 33
  • 63
3
votes
1 answer

boost::program_option::store throws exception when option string contains mixed language characters

I have simple code that works perfectly well with input option contains just ASCII characters, but throws an exception with error message of "error: character conversion failed". Is there a solution? Background info: 1. Compiler and OS: VC++2012…
James
  • 31
  • 2
3
votes
2 answers

UTF-16 codecvt facet

Extending from this questions about locales And described in this question: What I really wanted to do was install a codecvt facet into the locale that understands UTF-16 files. I could write my own. But I am not a UTF expert and as such I am sure I…
Martin York
  • 257,169
  • 86
  • 333
  • 562
3
votes
4 answers

Index and histogram of Unicode characters in input using C++

count the occurrences of each symbol and the location they appear in the text, word or line I have a list of words like so in many languages. What I am trying to do it count the occurrences of each character and the position in the text where they…
zeitue
  • 1,674
  • 2
  • 20
  • 45
2
votes
1 answer

What happens if I imbue basic_stream with locale with codecvt_utf16 facet?

Is it specified what will happen if I imbue basic_stream with locale with codecvt_utf16 facet? Basically, I use typedef wchar_t tchar; and typedef char tchar; to alter interfaces for (what I call) Unicode and non-Unicode builds of my…
wilx
  • 17,697
  • 6
  • 59
  • 114
2
votes
1 answer

When is std::codecvt::always_noconv() required to return true?

Does the standard (C++17) mandate that std::codecvt::always_noconv() returns true for all locales, or for locales provided by the implementation, or only for the C locale, or something else? The C++ standard does have…
Kristian Spangsege
  • 2,903
  • 1
  • 20
  • 43
2
votes
1 answer

Portable conversion of std::string to std::wstring and vice versa?

I need to convert std::string to std::wstring. I have used something on below lines with visual studio 2010 (and it's working fine) :- std::wstring_convert> converter; std::string narrow =…
ravi
  • 10,994
  • 1
  • 18
  • 36
2
votes
3 answers

Codecvt doesn't work in gcc

I'm trying to use my own codecvt with standard iostreams. I'm using this line: std::cout.imbue(std::locale(std::locale("C"), new rot13codecvt())); rot13codecvt is just an example, shamelessly lifted verbatim from the interwebs. A full runnable…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
2
votes
1 answer

Writing UTF16 file with std::fstream

Is it possible to imbue a std::fstream so that a std::string containing UTF-8 encoding can be streamed to an UTF-16 file? I tried the following using the utf8-to-utf16 facet, but the result file is still UTF-8: std::fstream utf16_stream("test.txt",…
Joris Timmermans
  • 10,814
  • 2
  • 49
  • 75
2
votes
0 answers

Possible buffer overflow bug in std::use_facet::out()

I think I have found a buffer overflow bug in the VC++10 std::locale object. I would be grateful for second opinions as to whether I am doing something wrong. The code below is simplified to demonstrate the problem. I am trying to convert a…
Michael J
  • 7,631
  • 2
  • 24
  • 30
1
vote
1 answer

Specializing codecvt: linker errors when third template argument is not std::mbstate_t

Given #include struct Q; struct R{ void operator()(Q*) { } }; class S : public std::codecvt { } ; int main() { char *p; char *q; const char *r; char *s; char *t; char *u; Q* _q; …
moshbear
  • 3,282
  • 1
  • 19
  • 33
1
vote
1 answer

Is there a codecvt decoding scenario where the destination buffer needs space for more than one internal character?

When using std::codecvt's in method to decode an external byte sequence to an internal char sequence, is there a situation where the destination buffer of internal chars needs space for more than one internal char? Here is some code for…
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
1
vote
1 answer

How to correctly use codecvt_byname (C++17) to encode latin1, and then UTF-8 for use in JSON

I am (desperately) trying to prepare a byte array (copied from a PLC, where they construct the "string" as a byte array, locale/encoding is German, French, etc) for use in nlohmann::json, while preserving the source encoding (latin1). Using this toy…
juwalter
  • 11,472
  • 5
  • 19
  • 18
1
vote
2 answers

Why std::basic_fstream won't work?

When trying to compile this code: std::fstream file("file.name", std::ios::out | std::ios::binary); uint8_t buf[BUFSIZE]; //Fill the buffer, etc... file.write(buf, BUFSIZE); compiler will give me warning about oh-not-so-healthy conversion from…
PookyFan
  • 785
  • 1
  • 8
  • 23
1
vote
1 answer

Difference between "codecvt_utf8_utf16" and "codecvt_utf8" for converting from UTF-8 to UTF-16

I came across two code snippets std::wstring str = std::wstring_convert>().from_bytes("some utf8 string"); and, std::wstring str = std::wstring_convert>().from_bytes("some utf8…
user963241
  • 6,758
  • 19
  • 65
  • 93