If your compiler doesn't allow you to write that (most compilers do), use wstring, that is, wstring word1 = L"débarquer";
Another way to write it in modern C++ is UTF-8, that is string word1 = u8"débarquer";
OK, then I'll have to change the compiler. Right now, I am using Codeblocks. What (free) compiler would you recommend? That allows you to use these characters?
Code::Blocks uses GCC by default, most likely already support it already. Use UTF-8 encoding when saving the file from IDE settings.
EDIT: Tried with Code::Blocks default settings and it works as expected. Please note that this is not a console project, outputting non-ascii characters to a console is not an easy thing to do.
UTF-8 that's awesome! Thanks so much Cubbi had no idea!
Also, é is ANSI-ASCII. It should work in a normal char string and output correctly in the Windows console (but it won't work on Linux which uses just base ASCII).
EDIT: I love having a British keyboard, we can type é so easily. Do US keyboards have that too, out of interest? I'm pretty sure French keyboards do...
Linux uses UTF-8 pretty much always these days, so é, Ж, 猫, etc, in a regular std::string stores and outputs just fine. As intended in C and C++: both languages use multibyte character encoding for character strings, conversions, and I/O.
(conversions and I/O may require setlocale/locale::global of course)
@xantavis
wstring/L"" is the code page UTF-16. It doesn't help either. the windows console has its own code page which is not ASCII. Changing the code page to UTF-8 suffice with SetConsoleOutputCP() for windows. Then you can use cout without problems
Windows has its own version of ANSI extended ASCII. In fact I don't think it was ever approved by ANSI. Also I think it changes the codes for different languages (to give support for other languages in a non-Unicode program), and for all we know it doesn't do that in the Command Prompt.
I made a quick test program for this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main()
{
// First output all readable codes.
for (unsignedchar i = 0x20U; i; ++i) {
std::cout << (unsigned) i << '\t' << i << std::endl;
}
// Then output specifically the 'é' character and its code.
std::cout << std::endl << std::endl <<
(unsigned) ((unsignedchar) 'é') << '\t' << 'é' << std::endl;
return 0;
}
Which gives output (with double ellipses for brevity) :
thanks for the link, but I dont understand it. As a rookie, this is to complicated for me. But Id like to make a simple program (for me). As it is in french, i'd need the non-english characters. So could you maybe write an example function? Then I would only insert where I have to. And if I have devoloped enough, then I might also try to understand it. Its not professional, I know, but it should do the work.