n. m. could be an AI
n. m. could be an AI

Reputation: 120079

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 example is here. My real codecvt does something different.

As you can see in the linked live example, this doesn't quite work in g++. The output is not rot13d. No function from the custom codecvt class is ever called. But it works well in VS2012.

I have tried other locales beside "C" and none are working. Also tried an example here, same result.

What am I doing wrong?

Upvotes: 2

Views: 4662

Answers (3)

thakis
thakis

Reputation: 5919

The codecvt header exists as of gcc 5.1.

Upvotes: 3

Dietmar Kühl
Dietmar Kühl

Reputation: 154035

Only file streams are required to use std::codecvt<...> and there is no requirement that any of the standard stream objects is implemented in terms of file streams. There are reasons for the implementers of either choice. Dinkumware's implementation uses <stdio.h> for most of its operations and it makes sense to use the same implementation under the hood in this case. libstdc++ avoids some overheads and directly accesses a buffer shared between the standard C and C++ streams and, thus, uses a different stream implementation.

When using file streams use of the std::codecvt<...> facets should be consistent.

Upvotes: 2

fjardon
fjardon

Reputation: 7996

The libstdc++ provided with g++ doesn't implement the c++11 standard yet. On my version, the <codecvt> header is missing altogether.

f.jardon@xxxx 14:40:40 ~
$ find /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/ -name codecvt

f.jardon@xxxx 14:41:17 ~

And it's not the only thing missing:

f.jardon@xxxx 14:46:22 ~
$ grep -rl wbuffer_convert 'c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include/'
c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include/cvt/wbuffer
c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include/cvt/xtest
c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include/xlocbuf

f.jardon@xxxx 14:46:25 ~
$ grep -rl wbuffer_convert /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/

Upvotes: 0

Related Questions