Problem with some characters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
    string str;

    cout << "Input:";
    cin >> str; //type in "ó"
    cout << "\nOutput 1: " << str;

    str = "ó";
    cout << "\nOutput 2: " << str;

    return 0;
}


Input:ó

Output 1: ó
Output 2: ≤


When you see Input: type in ó .

Why are the 2 outputs different? How could I fix this?
As i can see you're trying to display a central european language letter. You have to change code page to 1250, so write this peace of code:

system("chcp 1250");

in the beginning of main() function. You can also check which code page is active currently. All you've got to do is turning on console, and write "chcp". Windows default is 852, as I remember correctly.
Thanks! But is there any way to do this without using a "system" call?
I can't check it now, by try this:

setlocale(LC_ALL, "");

It will work, when you include locale.h file.
I got the same outputs...
I don't have any other idea. If you don't have to print variables like 'str', u can do this:

cout<<"\242"<<endl;

Why can't you use "system" call?
I've been advised to not use system calls such as system("Pause"). I forget why. Anyways could you take a look at my other post? This one is just a shorter version of the problem in my other source.

http://www.cplusplus.com/forum/general/27156/
Topic archived. No new replies allowed.