stringstream 操纵器 & VS工作室2003
我正在尝试在 VC++ (VStudio 2003) 中使用 stringstream 对象,但是当我使用重载的 << 时,出现错误。 操作员尝试设置一些操纵器。
我正在尝试以下操作:
int SomeInt = 1;
stringstream StrStream;
StrStream << std::setw(2) << SomeInt;
这不会编译(错误 C2593:“运算符 <<”不明确)。
VStudio 2003 支持以这种方式使用操纵器吗?
我知道我可以直接在 stringstream 对象上设置宽度,例如 StrStream.width(2);
我想知道为什么更常用的方法不起作用?
I am trying to use a stringstream object in VC++ (VStudio 2003) butI am getting an error when I use the overloaded << operator to try and set some manipulators.
I am trying the following:
int SomeInt = 1;
stringstream StrStream;
StrStream << std::setw(2) << SomeInt;
This will not compile (error C2593: 'operator <<' is ambiguous).
Does VStudio 2003 support using manipulators in this way?
I know that I can just set the width directly on the stringstream object e.g. StrStream.width(2);
I was wondering why the more usual method doesn't work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确定包含了所有正确的标头吗? 我在 VS2003 中编译的结果如下:
Are you sure you included all of the right headers? The following compiles for me in VS2003:
我喜欢这个参考网站来解决此类问题。
/艾伦
I love this reference site for stream questions like this.
/Allan
您可能只是忘记包含 iomanip,但我不能确定,因为您没有在那里包含完整程序的代码。
这个完整的程序在这里使用 VS 2003 运行良好:
You probably just forgot to include iomanip, but I can't be sure because you didn't include code for a complete program there.
This complete program works fine over here using VS 2003: