I have a bunch of code that looks like:
// Local block scope
{
ostringstream ostr;
ostr.fixed;
ostr.precision(2);
ostr.width(20);
ostr << foo->bar[trno];
SafeArrayPut2D( retArray, 3, i, (void *) ostr.str().c_str() );
}
{
ostringstream ostr;
ostr.fixed;
ostr.precision(4);
ostr.width(22);
ostr << foo->foobar[trno];
SafeArrayPut2D( retArray, 4, i, (void *) ostr.str().c_str() );
}
So I wanted to write a function to abbreviate the process. Here's what I did. In the header file:
void ostreamStringHelper( ostringstream& oss, streamsize prec, streamsize width );
In the cpp file:
void ostreamStringHelper( ostringstream& oss, streamsize prec, streamsize width )
{
oss.fixed;
oss.precision(prec);
oss.width(width);
}
However, it's giving me errors:
1>Compiling...
1>SafeArrayUtil.cpp
1>c:\safearrayutil.cpp(32) : error C2027: use of undefined type 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1>c:\safearrayutil.cpp(32) : error C2228: left of '.fixed' must have class/struct/union
1>c:\projects\cashflow\trancheinfodll\safearrayutil.cpp(33) : error
I don't understand --- what exactly is the problem with the ostreamStringHelper() function? oss is a reference to a class, not a pointer; why is the syntax invalid?
Thanks!