How to convert 32-bit character string to char string in C++

1 Answer

0 votes
#include <iostream>
#include <uchar.h>

int main(void) {
   const char32_t arr32[] = U"C++ Programming";
   char arr[32];
   mbstate_t mbs{};
   size_t len;
   int j = 0;
   
   while (arr32[j]) {
      len = c32rtomb(arr, arr32[j], &mbs); 
      if ((len == 0) || (len > 32))
         break;
      for (int i = 0; i < len; ++i)
         std::cout << arr[i];
         j++;
   }
}



/*
run:

C++ Programming

*/

 



answered Aug 2, 2020 by avibootz
edited Aug 2, 2020 by avibootz
...