2008-09-16 30 views
0

我想在VC++(VStudio 2003)中使用stringstream对象,但当我使用超载的< <运算符来尝试设置某些操纵器时,出现错误。stringstream操纵器&vstudio 2003

我尝试以下操作:

int SomeInt = 1; 
stringstream StrStream; 
StrStream << std::setw(2) << SomeInt; 

这不会编译(错误C2593: '运营商< <' 不明确)。
VStudio 2003是否支持以这种方式使用操纵器?
我知道我可以直接在stringstream对象上设置宽度,例如StrStream.width(2);
我想知道为什么更常用的方法不起作用?

回答

1

你确定你包含所有正确的标题?以下为我在VS2003编译:

#include <iostream> 
#include <sstream> 
#include <iomanip> 

int main() 
{ 
    int SomeInt = 1; 
    std::stringstream StrStream; 
    StrStream << std::setw(2) << SomeInt; 
    return 0; 
} 
+0

我失踪头。非常感谢! – 2008-09-16 06:23:07

0

你可能只是忘了,包括了iomanip,而是因为你没有包括一个完整的程序代码,有我不能肯定。

这个完整的程序工作正常,在这里使用VS 2003:

#include <sstream> 
#include <iomanip> 

int main() 
{ 
    int SomeInt = 1; 
    std::stringstream StrStream; 
    StrStream << std::setw(2) << SomeInt; 
}