Skip to content

Instantly share code, notes, and snippets.

@varvir
Last active November 13, 2020 14:29
Show Gist options
  • Save varvir/cd868c7aa4f15119a3f6bb19683f59ee to your computer and use it in GitHub Desktop.
Save varvir/cd868c7aa4f15119a3f6bb19683f59ee to your computer and use it in GitHub Desktop.
MacOS utf8 encoding test
#include<iostream>
#include<locale>
#include<string>
using namespace std;
int main()
{
locale myloc("<local machine locale or current locale>");
cin.imbue(myloc);
cout.imbue(myloc);
string name;
cout << "이름을 입력하세요(input your name): ";
cin >> name;
cout << name << "님 안녕하세요!(hello, <name>!)" << endl;
cout << name.size() << "글자 이군요(your name consist of <num> letters" << endl;
return 0;
}
@varvir
Copy link
Author

varvir commented Nov 13, 2020

"" 넣었을 때 myloc의 기본 locale이 출력되진 않았지만(걍 빈줄), MacOS도 UTF-8이 기본으로 되어있음을 알 수 있었다. size()에서 9가 나왔다. 한 글자를 3바이트로 인식했기 때문이다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment