keith
keith

Reputation: 5352

std::stringstream equivalent for u32string?

Is there an equivalent to std::stringstream which will allow me to build a std::u32string? If not how could I build up a std::u32string from lots of variable length pieces of text consisting of char32_t data?

Upvotes: 8

Views: 1634

Answers (2)

Phil Rosenberg
Phil Rosenberg

Reputation: 1809

Although the other answers are correct, that in theory this is fine. In practice it is not always so for all functionality.

Using (some versions of?) Visual Studio, the locales do not seem to work properly for char16_t and char32_t character types. These are used to get the decimal and thousand separator. Hence if you try to add a number to the stream you will receive a compilation error. I know this is at least the case for the version I am using VS 2019 4.8.03752.

Upvotes: 2

Akira
Akira

Reputation: 4473

The std::stringstream is a typedef:

typedef basic_stringstream<char> stringstream;

Therefore you can specialize the std::basic_stringstream<T> to your needs:

typedef std::basic_stringstream<char32_t> u32sstream;

Upvotes: 8

Related Questions