Writing unicode strings in C ++ for sqlite DB

I am currently creating a managerial game using sqlite and C ++. I found tutorials to cover almost every area needed to create my game, but the little problem annoyed me for ages.

when I write a string in C ++, for example "Andreas Klöden", and use it with the sqlite operator to insert data into my sqlite database, special characters with umlaut ö are lost, this applies to many European names such as Léfevre, Würth, etc. .

I was looking for an answer, it seems that C ++ strings are in ANSII or something like that. Somehow, I have to write unicode strings instead to avoid the problem shown below:

http://imageshack.dk//viewimage.php?file=/imagesfree/0Ej53884.png

Does anyone know how to write unicode strings in C ++ so that I can export / import the correct data from sqlite database?

+5
source share
2 answers

SQLite supports "UTF-8" (quotation marks here, because mostly UTF8 uses ASCII characters, so there really is nothing to "support"). Thus, one of the best (as well as backward compatible) ways is to use UTF-8 encoding. SQLite also has wchar_t support, but there is only one reason to use it: if the code already depends on wchar_t.

Read this if “UTF-8” is not a familiar topic: http://www.joelonsoftware.com/articles/Unicode.html

API C call

sqlite_exec(db_conn, "insert somevalue into sometable values(\"utf encoded string\""), NULL, NULL, "error");

will do the job.

, ICU . , http://utfcpp.sourceforge.net/

CodeProject UTF-8:

http://www.codeproject.com/Articles/14637/UTF-8-With-C-in-a-Portable-Way

http://www.codeproject.com/Articles/5281/UTF-8-Encoding-and-Decoding

.

+4

CppSqlite3U sqlite3, UNICODE. CppSqlite3U UNICODE.

-1

All Articles