fork download
  1. #include <cassert>
  2. #include <cuchar>
  3. #include <string>
  4.  
  5. int main() {
  6. std::u32string u32 = U"this is a wide string";
  7. std::string narrow = "this is a wide string";
  8. std::string converted(1000, '\0');
  9. char* ptr = &converted[0];
  10. std::mbstate_t state {};
  11. for(auto u : u32) {
  12. ptr += std::c32rtomb(ptr, u, &state);
  13. }
  14. converted.resize(ptr - &converted[0]);
  15. assert(converted == narrow);
  16. }
  17.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:18: error: cuchar: No such file or directory
prog.cpp: In function ‘int main()’:
prog.cpp:6: error: ‘u32string’ is not a member of ‘std’
prog.cpp:6: error: expected `;' before ‘u32’
prog.cpp:10: error: a function-definition is not allowed here before ‘{’ token
prog.cpp:11: error: a function-definition is not allowed here before ‘:’ token
prog.cpp:14: error: could not convert ‘converted.std::basic_string<_CharT, _Traits, _Alloc>::resize [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((unsigned int)(((int)ptr) - ((int)converted.std::basic_string<_CharT, _Traits, _Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](0u)))))’ to ‘bool’
prog.cpp:15: error: expected `)' before ‘;’ token
stdout
Standard output is empty