For shame

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31901

Because of this, I cannot use std::ostreambuf_iterator<uint32_t>.

It's alright, I'll just use std::copy() instead, along with some reinterpret_cast<const char *> ().
I mean, what's the difference, right? It's still ugly C++ code, just uglier.
Why would you want to use std::uint32_t as a character type?
Use char32_t instead?

std::ostreambuf_iterator<char32_t> works with GCC 4.7.2 and clang 3.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>

int main()
{
    std::basic_ostringstream<char32_t> stm ;
    const char32_t a[] = U"0123456789" ;

    std::copy( a, a+10, std::ostreambuf_iterator<char32_t>(stm) ) ;

    auto str = stm.str() ;
    for( auto i : str ) std::cout << int(i) << '\n' ;
}
This code creates an empty file named test.txt. Does it work for you?
(Using nuwen's MinGW 4.7.2.)

1
2
3
4
5
6
7
8
9
10
11
#include <iterator>
#include <algorithm>
#include <fstream>

int main()
{
    std::basic_ofstream<char32_t> stm("test.txt") ;
    const char32_t a[] = U"0123456789" ;

    std::copy( a, a+10, std::ostreambuf_iterator<char32_t>(stm) ) ;
}

GCC has not implemented the unicode code conversion facets; #include <codecvt> gives an error.
So we won't be able to imbue a locale with std::codecvt_utf16<char32_t> to a stream.

char32_t works on string streams because no code conversion is required.
Last edited on
Topic archived. No new replies allowed.