1 year ago
#379454
InquisitiveFly
My C++ Visual Studio program ignores the Swedish characters å, ä, and ö during input via Win terminal
I've encountered a, hopefully, slight problem during a programming endeavor inside Visual Studio 2022 on Windows 11!
Whenever I input å, ä, and ö into my running program using a getline into a string variable, it simply ignores these characters. For example, if I input the Swedish name Måns, the string variable then holds "m" but not "åns", and if I input Bergström, it holds "Bergstr" but not "Öm". The windows terminal outputs the former letters correctly, and when I read them from a text file they store properly into a string. The problem occurs only when I input these via the windows terminal; then the string variable omits the aforementioned characters.
What I've tried to do:
- Saved all pertinent file encodings to either Unicode (UTF-8 without signature) - Codepage 65001, Nordic (DOS) - Codepage 865, or Western European - Codepage 1252
- Used std::setlocale(LC_ALL, "") and std::setlocale(LC_ALL, "sv_SE.UTF-8")
- Went into the Windows settings -> Time & language -> Language & Region -> Administrative language settings -> Change system language -> checked a box saying "Beta: use Unicode UTF-8 for global language support"
I'm pretty lost, to say the least haha
Could anyone help me, please? :)
(By the way, I am a big programming newbie, so I don't think I'll understand much advanced or verbatim code stuff.)
Minimal reproducible code example:
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::string getTextFromFile,
stand, input;
stand = "Mjölk";
std::cout << stand << std::endl; //correctly outputs "Mjölk" into the terminal
std::fstream file("names.txt"); //file with words having the Swedish letters å, ä, and ö.
file >> getTextFromfile; //let's say it now includes "Måns".
std::cout << getTextFromFile << std::endl; //correctly outputs "Måns" into the terminal.
std::getline(std::cin, input); //we input "Måns"
std::cout << input << std::endl; //only outputs "M"; "åns" is missing.
return 0;
}
c++
utf-8
character-encoding
visual-studio-2022
windows-11
0 Answers
Your Answer