Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Created October 29, 2020 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoyBellingan/1c6939684085412d5a47fedc95d9c122 to your computer and use it in GitHub Desktop.
Save RoyBellingan/1c6939684085412d5a47fedc95d9c122 to your computer and use it in GitHub Desktop.
arab1.cpp
#include <codecvt>
#include <fmt/format.h>
#include <iostream>
#include <locale>
int main() {
std::string bytestring = "ئەرەب ئەلىفبەسى";
std::cout << bytestring << "\n";
fmt::print("{} contains {} byte, no idea of the char \n", bytestring, bytestring.size());
//Declare from which encoding to which one you want to perform the conversion
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(bytestring);
//this is not working
//std::cout << wide << "\n";
//fmt::print("{} contains {} byte, no idea of the char \n", wide, wide.size());
fmt::print("{} contains {} byte and {} character \n", bytestring, bytestring.size(), wide.size());
}
produces
ئەرەب ئەلىفبەسى
ئەرەب ئەلىفبەسى contains 29 byte, no idea of the char
ئەرەب ئەلىفبەسى contains 29 byte and 15 character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment