Assuming your source code is encoded in UTF-8 (there should be a setting in your editor that allows you to change this), all you have to do is make sure that the console's encoding is set to UTF-8 too and its font supports Greek characters. I'm on Linux Mint KDE, and compiling and running the following works as expected, since the conditions I mentioned above hold by default:
1 2 3 4 5 6 7 8
|
#include <iostream>
int main() {
std::cout << "- Τι κάνεις;" << std::endl;
std::cout << "- Καλά! Εσύ;" << std::endl;
std::cout << "- Καλά κι εγώ!" << std::endl;
}
|
On Windows, things are a little trickier... Try googling 'windows console UTF-8' and follow what instructions you find. If that doesn't work, try the same for UTF-16. Be careful though; you'll have to either change your source encoding to UTF-16 too, or use e.g. C++11 UTF-16 string literals [1].
BTW, you can use plain
std::strings to hold UTF-8/16 strings, but you should be aware that some operations, like getting the length of the string, will break, because of the variable-length nature of the encoding. If you want to perform such operations safely, the simplest way IMO is to first convert your strings to a fixed-length encoding (e.g. UTF-32 - in which case you can store a string as an
std::vector<uint32_t>) and perform the operations there. A very convenient and lightweight (header-only) library that can help here is utfcpp [2].
[1]
http://en.cppreference.com/w/cpp/language/string_literal
[2]
https://github.com/nemtrif/utfcpp