473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

[C++] strange problem with std::ostringstream

Hi ! I have a strange problem with a std::ostringstream..

code :
#include <sstream>

/*...*/

std::ostringstream ss();
ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\" \"\""
<< outfilename << "\"\""; //line 75

std::string callstring = ss.str(); //line 77

/* ... */

I don't have a undeclared identifier error when declaring std::ostringstream
ss();
however, I have thoses stranges errors :

c:\documents and settings\eric\mes documents\programming\stdcpp dynamic
code\loadlib.hpp(75) : error C2296: '<<' : illegal, left operand has type
'class std::basic_ostringstream<char,struct std::char_traits<char>,class
std::allocator<char> > (__cdec
l *)(void)'
c:\documents and settings\eric\mes documents\programming\stdcpp dynamic
code\loadlib.hpp(75) : error C2297: '<<' : illegal, right operand has type
'char [3]'
c:\documents and settings\eric\mes documents\programming\stdcpp dynamic
code\loadlib.hpp(77) : error C2228: left of '.str' must have
class/struct/union type
I use vc++ 6.0

that's a very strange error and I really do not have a clue how to solve
it.. I mean.. ss is not a undeclared identifier.. and it's really defined
as a std::ostringstream.. but I have thoses errors...
any help appreciated.. really !!

thanks !

-Eric Boutin
Jul 22 '05 #1
6 2978
Eric Boutin wrote in news:t_**********************@weber.videotron.net:

This:
std::ostringstream ss();


is a function declaration

std::ostringstream ss( void );

change it to

std::ostringstream ss;

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
This is a normal behavior or a behavior from a crappy compiler ?

"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> a écrit dans le message de
news:Xn**********************************@195.129. 110.130...
Eric Boutin wrote in news:t_**********************@weber.videotron.net:

This:
std::ostringstream ss();


is a function declaration

std::ostringstream ss( void );

change it to

std::ostringstream ss;

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Jul 22 '05 #3
Eric Boutin wrote in news:eW********************@wagner.videotron.net:
This is a normal behavior or a behavior from a crappy compiler ?


Its normal standard conforming behaviour.

[snip]. <<-- hint

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
On 03 Dec 2003 11:54:53 GMT, Rob Williscroft
<rt*@freenet.REMOVE.co.uk> wrote:
Eric Boutin wrote in news:eW********************@wagner.videotron.net:
This is a normal behavior or a behavior from a crappy compiler ?


Its normal standard conforming behaviour.

[snip]. <<-- hint

Rob.


I've always been a bit confused by declarations of variables
explicitly calling the default constructor. And now I wonder how would
the compiler not interpret

std::ostringstream ss();

as a forward declaration of a function returning an ostringstream.
When exactly is it necessary to add "()" to class instantiation?

Would that only be when instantiating a derived type in the argument
list of a function call like

class bar {};
void foo(bar);
class dbar : bar {};
...........
foo( dbar temp_db() );
?

dan
Jul 22 '05 #5
Dan W. wrote in news:8j********************************@4ax.com:
On 03 Dec 2003 11:54:53 GMT, Rob Williscroft
<rt*@freenet.REMOVE.co.uk> wrote:
Eric Boutin wrote in news:eW********************@wagner.videotron.net:
I've always been a bit confused by declarations of variables
explicitly calling the default constructor. And now I wonder how would
the compiler not interpret

std::ostringstream ss();

as a forward declaration of a function returning an ostringstream.
When exactly is it necessary to add "()" to class instantiation?
Well never (almost). You could write:

std::ostringstream ss = std::ostringstream();

Unfortunatly it won't work in this case as the streams lack copy-ctor's
but *fortunatly* it unnesassery as the compiler will default construct
ss for you anyway.

Would that only be when instantiating a derived type in the argument
list of a function call like

The one and only time it's truly usefull to explicitly call a default
constructor is when initialising a POD (int, double, struct without
constructors etc).

struct X
{
int a; /* a is POD no default constuctor */
X() : a() {}
};

Though a( 0 ) would be just as good above. This is truly usfull within
templates.

template < typename T > struct Y
{
T b;
Y() : b() {}
};

Now Y::b is properly initialized even if T is a type (say int)
without a default constructor. Also unless for some reason we
know that T will always be initializable from 0, b( 0 ) won't
work.
class bar {};
void foo(bar);
class dbar : bar {};
..........
foo( dbar temp_db() );


Did you mean

foo( bar() );

or maybe

foo( dbar() ); // watch the slicing !!
struct Z { /*whatever*/ };

int foo( Z const &z = Z() )
{
return 0;
}

Not from all of the above the only place I write variable_name() is
in the initialization list of stucts X and Y, otherwise its type().
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6
Thank you!

I guess I had foggy memories coming up, like in nameless temporary
construction, such as

class foggy_memory {};
....
throw( foggy_memory() );

Such off sightings often throw me off for a sec... ;-)
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris | last post by:
Hi, I'm playing/developing a simple p2p file sharing client for an existing protocol. A 2 second description of the protocol is Message Length = int, 4 bytes Message Code = int, 4 bytes...
6
by: Christopher Benson-Manica | last post by:
Is there anything that one can do to a std::ostringstream that would make its destructor explode? I'm basically doing { std::ostringstream ss, msg; // do BUNCHES of stuff with ss and msg ...
5
by: Simon Pryor | last post by:
I am having some strange problems using std::ostringstream. The simple stuff works okay, but trying to use: std::ostringstream::str(const std::string&) or:...
1
by: Jason Heyes | last post by:
I would like to have std::cout redirect its output to a std::ostringstream. Can this be done? Help is appreciated.
5
by: sleepydj | last post by:
Hello, I have a simple program to create strings from the corresponding double/integer values. For any data type similar to int, I have a template set up in a file misc.h: ...
2
by: bob | last post by:
For reasons that are irrelevant , we cannot use sprintf to do conversions between doubles, ints etc. to char*. We're using the std::ostringstream type. Basically we have a function that takes a...
4
by: Olaf van der Spek | last post by:
Hi, I'm using ostringstream and I'd like to generate \r\n line ends instead of \n ones. Is there a flag for this? Or should I just insert the \r myself?
3
by: Generic Usenet Account | last post by:
With the deprecated ostrstream class, when the constructor is invoked without arguments, memory is dynamically allocated. In that case the onus on freeing the memory lies with the user. Typically...
25
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.