How to convert an ASCII string to an UTF8 string in C++?

How to convert an ASCII std::string to an UTF8 (Unicode) std::string in C++?

Answers


std::string ASCIIToUTF8(std::string str) {
  return str;
}

Every ASCII character has the same representation in UTF8, so there is nothing to convert. Of course, if the input string uses an extended (8-bit) ASCII character set, the answer is more complex.


ASCII is a seven-bit encoding and maps identically onto the UTF-8 encoding of the subset of characters that can be represented in ASCII.

In short, there is nothing to do. Your ASCII string is already valid UTF-8.


I assume that by ASCII you mean CP1252 or other 8 bit character set (ASCII is only 7 bits and it is directly compatible with UTF-8, no conversion required). Standard C++ cannot do it. You need e.g. Glibmm, Qt, iconv or WINAPI to do it.


Need Your Help

Relaxing Flash security for local swf accessing local files

c++ flash security actionscript chromium

Here's my situation - I have a 3D Engine written in C++ and DirectX. It uses Awesomium for GUI windows.

How we can integrate FreeRDP API in our android app to remotely share desktop?

rdp

How we can integrate FreeRDP Api in our android app to remotely share desktop? Is FreeRDP suppose 1 to many sharing ? I mean that can we share same desktop from multiple android devices in one time.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.