How can we convert u32string
to int
in C++11?
Additional, what method should I use to convert part of such string to int
- lets say having begin and end iterator available?
I've tried:
u32string test=U"14";
cout << atoi(test.c_str());
but it throws:
candidate function not viable: no known conversion from 'const char32_t *' to 'const char *' for 1st argument
extern int atoi (__const char *__nptr)
This depends on UTF-8 and the "C" locale using the same representation for digits.
GCC's standard library implementation libstdc++ does not include the codecvt header or std::wstring_convert yet. libc++ does include both of these, as does Visual Studio's standard library implementation. If you have to use libstdc++ you may find it easiest to just implement a simple conversion function yourself.
Edited because my first answer was stupid.
Here is what i managed to do, however its probably not very efficient, and it assumes your string is valid.