I'm working with strings in C++, and have a question about how norwegian characters are treated.
If I run the following code;
int main()
{
string norwegian = "BLÅBÆRSYLTETØY";
for (auto &c : norwegian)
cout << c << " => " << static_cast<int>(c) << endl;
return 0;
}
the output at cmd becomes:
B => 66
L => 76
┼ => -59
B => 66
ã => -58
R => 82
S => 83
Y => 89
L => 76
T => 84
E => 69
T => 84
Ï => -40
Y => 89
Notice that the three norwegian characters are not printed correctly, and that the ASCII value is negative.
Is there any way to treat the string so that it uses the correct charactermap?
EDIT
The solution is to change the codepage from ANSI to UTF-7, which can be done by adding this before the code that does stringhandling;
system("chcp 65000");