Stringstream操纵器和VStudio 2003
时间:2020-03-05 18:55:12 来源:igfitidea点击:
我正在尝试在VC ++(VStudio 2003)中使用stringstream对象,但是当我使用重载的<<运算符尝试设置一些操纵器时遇到错误。
我正在尝试以下方法:
int SomeInt = 1; stringstream StrStream; StrStream << std::setw(2) << SomeInt;
这将无法编译(错误C2593:"运算符<<"不明确)。
VStudio 2003是否支持以这种方式使用操纵器?
我知道我可以直接在stringstream对象上设置宽度,例如StrStream.width(2);
我想知道为什么更常用的方法不起作用?
解决方案
回答
我们确定包含所有正确的标题吗?以下在VS2003中为我编译:
#include <iostream> #include <sstream> #include <iomanip> int main() { int SomeInt = 1; std::stringstream StrStream; StrStream << std::setw(2) << SomeInt; return 0; }
回答
我喜欢这个参考站点,以解决像这样的流问题。
/艾伦
回答
我们可能只是忘了包含iomanip,但是我不确定,因为我们没有在其中包含完整程序的代码。
使用VS 2003,此完整程序可以在此处正常运行:
#include <sstream> #include <iomanip> int main() { int SomeInt = 1; std::stringstream StrStream; StrStream << std::setw(2) << SomeInt; }