This page has moved or been replaced. The new page is located here:

Please update any bookmarks that point to the old page.

Download this Manual
User Comments
  Posted by Atul Patil on July 4, 2015
Connector/C++ and Unicode (UTF-8):

If you have to populate utf8 VARCHAR type column, then you can do this:

1. First get the unicode string in wstring for example:
std::wstring wname = _T("अतुल");

2. Then convert the string above to utf-8 string using this function:
#include <codecvt>
#include <string>

// convert wstring to UTF-8 string
std::string wstring_to_utf8 (const std::wstring& str)
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.to_bytes(str);

Thus our string becomes:
std::string name = wstring_to_utf8(wname);

3. You can now use the obtained std::string in MySQL query:
std::string strQuery = "INSERT INTO ALL_USERNAMES (USERNAME) VALUES ('" + name + "')";

Sign Up Login You must be logged in to post a comment.