本文介绍了用 setw 截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法强制setw
截断?
Is there a way that I can force setw
to truncate?
说我想得到输出:
blah blah blee le
呜呜呜呜呜
有没有办法让这个工作:
Is there a way to make this work:
string foo{"bu blah blah blee le"};
cout << setw(foo.size() - 3) << foo.data() + 3 << setw(foo.size() - 3) << foo << endl;
推荐答案
不,不是真的.
您可以在此示例中切换到未格式化的输出:
You can switch to unformatted output for this example, though:
assert(foo.size() > 3);
cout.write(&foo[3], foo.size() - 3);
cout.write(&foo[0], foo.size() - 3);
这篇关于用 setw 截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!