input output of special characters

I am trying to get a simple console application together that can help my son practice his french verbes. Everything works fine but when typing the accents, a different symbol appears. For example the ê comes out as Û so instead of arrêter arrÛter appears so it is of no use

I know it has something to do with the console code page settings but I don't know how to go about changing them so that the accents come out fine. So how do I set them?
And if I change them, do i have to reset them before ending the program?
You have to use both SetConsoleCP() to set the input code page and SetConsoleOutputCP() to set the output code page.
http://www.google.com/search?btnI=1&q=msdn+SetConsoleCP
http://www.google.com/search?btnI=1&q=msdn+SetConsoleOutputCP

See also http://www.google.com/search?btnI=1&q=msdn+console+code+pages

Here is a list of code page identifiers:
http://www.google.com/search?btnI=1&q=msdn+code+page+identifiers

The code page you want is probably 1252 (ANSI Latin 1/Western European).


The change in code page only affects your application, IIRC, so you can set it at the beginning of your program and forget about it.

You also have to make sure, however, that the user has his console's font set to "Lucida Console" or whatever his system's Unicode console font is...

Hope this helps.
Thx Duoas but I kinda need a little more help as in the actual line of code that I would need to use

I found the msdn pages myself but don't know how to insert it into my code so gave up looking at them and looked for a forum to ask my question :P.

Not sure if this makes any difference but I use Visual C Express edition and on setup choose console application

I tried these lines

SetConsoleCP(1252);
SetConsoleOutputCP(1252);

but I keep getting "error C3861: 'SetConsoleCP': identifier not found" (in whatever form I tried them so also using "SetConsoleCP( __in 1252);" and other variations)

I am really new to programming and there are probably some things in my program that could be better but it works and it's only for short time usage... (I have read more of your answers and know you really don't like to see the usage of system("pause") hehe) only the accents come out wrong

It's just a small program to use in the family so if it doesn't work on his computer, he can do it on mine that's not a worry

here is part of the code (text to put on screen is in dutch in case you wondered)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include<string>
using namespace std;

void main()
{
	string werkwoord;

	cout << "Franse werkwoorden vervoegen" <<endl;
	cout << "Geef telkens de gevraagde vorm " <<endl << endl;

	cout << "amener participe présent:     ";
	cin >> werkwoord;
	cin.get();
	while (werkwoord != "amenant")
	{
		cout << "Niet juist. Probeer opnieuw: ";
		cin >> werkwoord;
		cin.get();
	}
	cout << "Prima" <<endl;
	system("pause");
}


Do I need to include a headerfile to be able to use these functions?

You need to #include <windows.h> to use SetConsoleCP(1252); and SetConsoleOutputCP(1252);.

Also, I recommend you replace all your cin.get();s with cin.ignore(numeric_limits<streamsize>::max(),'\n');.

And replace line 22 with
1
2
cout << "Druk RETURN om verder te gaan" << flush;
cin.ignore(numeric_limits<streamsize>::max(),'\n');

You'll have to #include <limits> to use the numeric_limits information.

Hope this helps.
It works now but unfortunately it still shows the same symbol

I have double checked by using the following code

1
2
3
4
5
6
	cout << GetConsoleCP() << "   " << GetConsoleOutputCP() << endl;

	SetConsoleCP(1252);
	SetConsoleOutputCP(1252);

	cout << GetConsoleCP() << "   " << GetConsoleOutputCP() << endl;


and while before resetting the code pages were 850, they are indeed set to 1252 afterwards, only ê still comes out as Û
I have tried every possible code I could see that has Latin1 in it (some of them are not supported by my computer and the code page stays on 850) but is does not make one bit of a difference. I keep getting the same symbols printed on screen.

Am I missing something here?
Topic archived. No new replies allowed.