473,666 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[C++] strange problem with std::ostringstr eam

Hi ! I have a strange problem with a std::ostringstr eam..

code :
#include <sstream>

/*...*/

std::ostringstr eam 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::ostringstr eam
ss();
however, I have thoses stranges errors :

c:\documents and settings\eric\m es documents\progr amming\stdcpp dynamic
code\loadlib.hp p(75) : error C2296: '<<' : illegal, left operand has type
'class std::basic_ostr ingstream<char, struct std::char_trait s<char>,class
std::allocator< char> > (__cdec
l *)(void)'
c:\documents and settings\eric\m es documents\progr amming\stdcpp dynamic
code\loadlib.hp p(75) : error C2297: '<<' : illegal, right operand has type
'char [3]'
c:\documents and settings\eric\m es documents\progr amming\stdcpp dynamic
code\loadlib.hp p(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::ostringstr eam.. but I have thoses errors...
any help appreciated.. really !!

thanks !

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

This:
std::ostringstr eam ss();


is a function declaration

std::ostringstr eam ss( void );

change it to

std::ostringstr eam 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.RE MOVE.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::ostringstr eam ss();


is a function declaration

std::ostringstr eam ss( void );

change it to

std::ostringstr eam ss;

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

Jul 22 '05 #3
Eric Boutin wrote in news:eW******** ************@wa gner.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.RE MOVE.co.uk> wrote:
Eric Boutin wrote in news:eW******** ************@wa gner.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::ostringstr eam 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.c om:
On 03 Dec 2003 11:54:53 GMT, Rob Williscroft
<rt*@freenet.RE MOVE.co.uk> wrote:
Eric Boutin wrote in news:eW******** ************@wa gner.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::ostringstr eam 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::ostringstr eam ss = std::ostringstr eam();

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
2796
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 Data
6
4840
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 // use ss.str() and msg.str(), apparently successfully
5
2361
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: std::ostringstream::ostringstream(const std::string&) Gives some weird results on both Solaris & Linux. Either that or I'm missing something. I've made a simple program to
1
2369
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
1688
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: ************************************************************************************* //misc.h #ifndef __MISC_H__ #define __MISC_H__
2
3542
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 double and needs to store a string representation of it into a vector of strings. ... something like this; void pussy::(const double d) { std::ostringstream strm;
4
4519
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
4069
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 this is done by obtaining the char buffer (by invoking the str() method) and then explicitly deleting it. Does the ostringstream class also have the same issue? I mean, if I instantiate ostringstream without any constructor arguments, is the...
25
8339
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
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.