This my code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
std::locale::global(std::locale("en_US.UTF-8"));
vector<string> msg{"Hello", "C++", "发多少", "from", "VS Code", "and the C++ extension!"};
for (const string &word : msg)
{
cout << word << " ";
}
cout << endl;
}
When I added std::locale::global(std::locale("en_US.UTF-8"));
, it shows right in vscode, otherwise no, even I have already used utf-8 encoding.
2