8

I have tried searching for a solution for this through this site and many others. I couldn't find an answer for it.

So, my problem would be to print special Scandinavian vowels such as Ä, Ö or Å in my console. Is it possible in c++ or not doable?

I tried searching ASCII codes through, but only found some other special characters.

Also, im just a very beginner in c++.

Thank you for your answers! :)

EDIT: For other very beginner programmers who haven't developed their skills much yet: I also found out a more beginner friendly (yet very time consuming and frustrating way) to print Scandinavian vowels in ASCII.

A snippet from code:

int main()
{
cout << "Kirjoitan t" << char(132) << "ss" << char(132)<< " huvikseni " <<;
cout << "Skandinaavisilla kirjaimilla p" << char(132) << "tk" << char(132) << "n." << endl;
return 0;
}

Which would obviously print out: "Kirjoitan tässä huvikseni Skandinaavisilla kirjaimilla pätkän." = "Im writing with Scandic alphabet just for fun."

It will just make your typing really messy and confusing.. Trying to learn the proper way to do it as i speak :)

user3476851
  • 115
  • 1
  • 7
  • Google for Unicode and character set – SJuan76 Mar 30 '14 at 19:17
  • What operating system are you uisng? Windows? Mac? Linux? – Johan Råde Mar 30 '14 at 19:22
  • Search on this site for "unicode console" and you will find several answers to your question. – Johan Råde Mar 30 '14 at 19:32
  • Thank you for your answers! I didnt know that i can use Unicode characters in c++. Thank you very much! :) – user3476851 Mar 30 '14 at 19:36
  • 2
    If you're on Windows, be aware that the console is basically broken wrt. Unicode. So you might find that you can write these characters to a file correctly, but they get mangled when written to the console. That's not because of your code, it's the Windows default console being... really really dumb. – jalf Mar 30 '14 at 19:38
  • 1
    @jalf: In Windows the native API (WriteConsole) works and the standard ones don't. – Jan Hudec Mar 31 '14 at 12:58
  • When you thought `åäö` weren't in ASCII you were **right**, they aren't. – Biffen Mar 31 '14 at 13:21
  • @Biffen Oh! Its fun to be a very beginner. Moment ago you think you know something, the next you think you don't and later you know that you we're kinda right in the first place. Hehe. Thanks for the answer! – user3476851 Mar 31 '14 at 21:41

1 Answers1

8

Try including clocale and calling

setlocale(LC_ALL, "utf-8");

or

setlocale(LC_ALL, "fi-FI");

early in your program (depending on what character set you are saving your .cpp files as). Depending on which compiler and platform you use, the language codes might be different; maybe you need just the language code "fi".

For other Scandinavian users, "nb-NO" (Norweigan Bokmål), "nn-NO" (Norwegian Nynorsk), "sv-SE" (Swedish), "sv-FI" (Swedish in Finland), or "da-DK" (Danish) should do the trick.

Also, read Joel Spolsky's excellent article about character sets and encodings.

Aasmund Eldhuset
  • 37,289
  • 4
  • 68
  • 81
  • Wow, that was really thorough answer! Thank you so much! :) I will try as you suggested! – user3476851 Mar 30 '14 at 19:35
  • I included but seems that i'm unable to set it properly. Atleast neither of the ones you suggested worked so far. – user3476851 Mar 31 '14 at 00:34
  • @user3476851: Which operating system do you use? If you are on Windows, what does the console command `chcp` tell you? – Aasmund Eldhuset Apr 01 '14 at 19:58
  • I'm using Windows 7. The command gave me: "Active code page: 850". – user3476851 Apr 01 '14 at 22:04
  • @user3476851: Try using File -> Advanced Save Options in Visual Studio (if that's the IDE you're using) and saving your file as "Western European (DOS) - Codepage 850", and simply write the Scandinavian characters direcly in your strings: `cout << "Kirjoitan tässä" << endl;`. Even if that works, you shouldn't use that outdated code page, so you might want to switch to UTF-8 encoding in your source files and [permanently change the code page of the console](http://stackoverflow.com/a/7511995/626853) to 65001. – Aasmund Eldhuset Apr 02 '14 at 10:42
  • @user3476851: If your console doesn't like UTF-8, try "Western European (Windows) - Codepage 1252" and `chcp 1252` instead. – Aasmund Eldhuset Apr 02 '14 at 10:51