When you write
cout << "\u2780";
The compiler converts \u2780 into the appropriate encoding of that character in the execution character set. That's probably UTF-8, and so the string ends up having four bytes (three for the character, one for the null terminator).
If you want to generate the character at run time then you need some way to do the same conversion to UTF-8 at run time that the compiler is doing at compile time.
C++11 provides a handy wstring_convert
template and codecvt facets that can do this, however libstdc++, the standard library implementation that comes with GCC, has not yet gotten around to implementing them (as of GCC 4.8.0 (2013-03-22)). The following shows how to use these features, but you'll need to either use a different standard library implementation or wait for libstdc++ to implement them.
#include <codecvt>
int main() {
char32_t base = U'\u2780';
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert;
std::cout << convert.to_bytes(base + 5) << '\n';
}
You can also use any other method of producing UTF-8 you have available. For example, iconv, ICU, and manual use of pre-C++11 codecvt_byname facets would all work. (I don't show examples of these, because that code would be more involved than the simple code permitted by wstring_convert
.)
An alternative that would work for a small number of characters would be to create an array of strings using literals.
char const *special_character[] = { "\u2780", "\u2781", "\u2782",
"\u2783", "\u2784", "\u2785", "\u2786", "\u2787", "\u2788", "\u2789" };
std::cout << special_character[i] << '\n';
L
? post your full code if possible or an [sscce.org](SSCCE) – Marcelmarcelax
instead of adding it. – Zillah