我的问题如以下最小示例所示:
#include <iostream>
#include <string>
#include <iomanip>
int main()
{
int width = 15;
std::cout << std::left;
std::cout << std::setw(width) << "Prints well" << std::setw(width) << "This too" << '\n';
std::cout << std::setw(width) << "\u221E" << std::setw(width) << "This not?" << '\n';
std::cout << std::setw(width+2) << "\u221E" << std::setw(width) << "This is good" << '\n';
}
使用 g++ 编译,它打印:
Prints well This too
∞ This not?
∞ This is good
因此,unicode 符号似乎使用了 setw 中的 3 个空格,而不是 1 个。有没有一种简单的方法来解决这个问题,事先不知道 unicode 字符是否会出现在字符串中?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)