【问题标题】:stringstream manipulators & vstudio 2003stringstream 操纵器和 vstudio 2003
【发布时间】:2008-09-16 05:59:39
【问题描述】:

我正在尝试在 VC++ (VStudio 2003) 中使用 stringstream 对象,但是当我使用重载的

我正在尝试以下方法:

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

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

【问题讨论】:

    标签: visual-studio stl


    【解决方案1】:

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

    #include <iostream>
    #include <sstream>
    #include <iomanip>
    
    int main()
    {
       int SomeInt = 1;
       std::stringstream StrStream;
       StrStream << std::setw(2) << SomeInt;
       return 0;
    }
    

    【讨论】:

      【解决方案2】:

      我喜欢 reference site 这样的直播问题。

      /艾伦

      【讨论】:

        【解决方案3】:

        您可能只是忘记包含 iomanip,但我不能确定,因为您没有在其中包含完整程序的代码。

        这个完整的程序在这里使用 VS 2003 运行良好:

        #include <sstream>
        #include <iomanip>
        
        int main()
        {
            int SomeInt = 1;
            std::stringstream StrStream;
            StrStream << std::setw(2) << SomeInt;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-10-20
          • 1970-01-01
          • 1970-01-01
          • 2018-07-07
          相关资源
          最近更新 更多