Created
October 29, 2020 20:04
-
-
Save RoyBellingan/1c6939684085412d5a47fedc95d9c122 to your computer and use it in GitHub Desktop.
arab1.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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