Non-English String Literals in C++ Source Code
When a C++ compiler compiles a C++ source file, it must process the bytes according to a character encoding and that is typically ANSI. ANSI is not a character encoding, it is simply a keyword that says “Use the default multi-byte character encoding for this computer based on its current locale.” Therefore, if your program is originally written in Poland and contains string literals (i.e. character string constants in double-quotes) with Polish characters, the same source when compiled on a typical computer in France will not produce the same results. The bytes for the Polish characters will instead be interpreted as Latin1 characters and the string will be different. This example demonstrates a technique you may use to embed string literals using quoted-printable so that the C++ source may be compiled on any computer without character encoding issues caused by the locale. Chilkat provides a free tool to quoted-printable encode a string (which may contain characters in any language):
Quoted-Printable Encoding Tool Download
Here is a screenshot:
The quoted-printable encoder is a very simple C# program that uses the Chilkat.CkString class. Here is the complete source code:
private void button1_Click(object sender, EventArgs e) { Chilkat.CkString str = new Chilkat.CkString(); str.append(textBox1.Text); str.qpEncode(comboBox1.Text); textBox2.Text = str.getString(); }
Using Quoted-Printable String Literals in C++
Use the tool to convert your string to quoted-printable using the utf-8 character encoding. (utf-8 is the multi-byte encoding for Unicode, so it is able to mix characters of any language in a single NULL-terminated string. A “multibyte” encoding is a character encoding such that each character is represented by one or more bytes, and there are no NULL bytes.)
Use the quoted-printable encoded string in your C++ source code like this:
(This example constructs an IMAP mailbox name using Vietnamese characters)
CkImap imap; bool success; ... CkString str; str.append("C=C3=B4ng c=E1=BB=99ng"); str.qpDecode("utf-8"); str.prepend("Inbox."); imap.put_Utf8(true); success = imap.CreateMailbox(str.getUtf8()); if (success != true) { printf("%s\n",imap.lastErrorText()); return; }