开发者

Is there an output equivalent to getline(cin, x) on C++?

开发者 https://www.devze.com 2023-02-03 06:48 出处:网络
I like how getline(cin, x) works for reading stuff. Unlike cin >> x, it doesn\'t me开发者_运维知识库ss up the buffer and it seems to allow European characters like á, é, etc too.

I like how getline(cin, x) works for reading stuff. Unlike cin >> x, it doesn't me开发者_运维知识库ss up the buffer and it seems to allow European characters like á, é, etc too. I was just wondering if there's an output equivalent to this, because cout << x doesn't allow European characters and maybe there's a better option than that.


You can try std::wcout, it is designed to support wide char strings and should work fine with european characters. It has the same usage as std::cout, but you will need the wide string literal prefix 'L':

std::wcout << L"My cool string.";


See Michael Kaplan’s blog for Unicode issues in Windows. For the console, especially the following posts are relevant:

  • Myth busting in the console
  • Conventional wisdom is retarded
0

精彩评论

暂无评论...
验证码 换一张
取 消