Advertisement
Advertisement


stringstream manipulators & vstudio 2003


Question

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?

2013/12/02
1
0
12/2/2013 1:38:38 PM

Accepted Answer

Are you sure you included all of the right headers? The following compiles for me in VS2003:

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

int main()
{
   int SomeInt = 1;
   std::stringstream StrStream;
   StrStream << std::setw(2) << SomeInt;
   return 0;
}
2008/09/16
1
9/16/2008 6:08:56 AM

I love this reference site for stream questions like this.

/Allan

2008/09/16

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:

#include <sstream>
#include <iomanip>

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