我的问题显示在以下最小示例中:
#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';
}
Run Code Online (Sandbox Code Playgroud)
使用 g++ 编译,它打印:
Prints well This too
? This not?
? This is good
Run Code Online (Sandbox Code Playgroud)
因此,unicode 符号似乎使用了 setw 中的 3 个空格而不是一个。有没有一种简单的方法可以解决这个问题,事先不知道字符串中是否会包含 unicode 字符?
| 归档时间: |
|
| 查看次数: |
518 次 |
| 最近记录: |