473,396 Members | 1,780 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.

std::ostringstream, urgent

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

printf( "Done\n" );
}

printf( "Out of scope\n" );

Before the program gets to the second printf, it completely dies. I
really don't want to use C-style character arrays to sub for a
stringstream, but if I can't make this work... Any help would be most
appreciated.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #1
6 4818
Christopher Benson-Manica wrote:
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

printf( "Done\n" );
}

printf( "Out of scope\n" );

Before the program gets to the second printf, it completely dies. I
really don't want to use C-style character arrays to sub for a
stringstream, but if I can't make this work... Any help would be most
appreciated.


This probably has nothing to do with std::ostringstream. You probably
have some memory corruption going on.

I suggest.

a) Try posing a *compilable* chunk-o-code that demonstrates your problem.

b) Try running your code under valgrind or purify.

Jul 22 '05 #2
Gianni Mariani <gi*******@mariani.ws> spoke thus:
This probably has nothing to do with std::ostringstream. You probably
have some memory corruption going on.
If it's memory corruption, I'm quite likely going to find out
unpleasantly at some random time in the future. FWIW, switching to
10K character buffers at least hides the problem, if there is one.
a) Try posing a *compilable* chunk-o-code that demonstrates your problem.
It's part of a server, and so posting compilable code is pretty much
out of the question...
b) Try running your code under valgrind or purify.


Also not possible, unfortunately. Dollars to donuts I'm just screwed,
but it probably isn't your fault ;) Anyway, thanks.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #3
Christopher Benson-Manica wrote:
Gianni Mariani <gi*******@mariani.ws> spoke thus:

This probably has nothing to do with std::ostringstream. You probably
have some memory corruption going on.

If it's memory corruption, I'm quite likely going to find out
unpleasantly at some random time in the future. FWIW, switching to
10K character buffers at least hides the problem, if there is one.


Slippery slope. Don't go there. It's allways easier to find the
problem and fix it. Knowing you have a problem that will bite you in
the future is going to make you sleep badly :-)...
a) Try posing a *compilable* chunk-o-code that demonstrates your problem.

It's part of a server, and so posting compilable code is pretty much
out of the question...

b) Try running your code under valgrind or purify.

Also not possible, unfortunately. Dollars to donuts I'm just screwed,
but it probably isn't your fault ;) Anyway, thanks.


What about efence ?
Unfortunate...

One of the tenets of good software is that it is testable.
Jul 22 '05 #4
Gianni Mariani <gi*******@mariani.ws> spoke thus:
Slippery slope. Don't go there. It's allways easier to find the
problem and fix it. Knowing you have a problem that will bite you in
the future is going to make you sleep badly :-)...
Yes, but not as badly as I'll sleep tonight if I don't get this
functionality working in the next couple of hours ;)
What about efence ?


The main reason none of these are possible is that the software runs
on a remote server, and thus we can't install such things at our
convenience. Unfortunate - you can say that again...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #5
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
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

printf( "Done\n" );
}

printf( "Out of scope\n" );
I'm assuming all of the above is in a function, otherwise the second
printf would be an error (why not use std::cout?)
Before the program gets to the second printf, it completely dies. I
really don't want to use C-style character arrays to sub for a
stringstream, but if I can't make this work... Any help would be most
appreciated.


Are you sure it dies *before* the second printf? You didn't do a
"fflush(stdout);", so if the program dies any buffered data may fail
to be flushed.

Try "std::cerr << "Out of scope\n" << std::endl;" to ensure this is
the case.

Next, run the program in a debugger. If you're using GDB:
$ gdb ./program
gdb> catch throw [break on exception thows]
gdb> run
[runs till there's an error]
gdb> backtrace [see where the failure really occured]
HTH,
Roger

--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #6
Roger Leigh <${******@invalid.whinlatter.uklinux.net.invalid > spoke thus:
I'm assuming all of the above is in a function, otherwise the second
printf would be an error (why not use std::cout?)
Yes, it's all in a function.
Are you sure it dies *before* the second printf? You didn't do a
"fflush(stdout);", so if the program dies any buffered data may fail
to be flushed.
Yes, I'm sure - the actual code ensures that, but I can see why you'd
be skeptical from what I posted. Sorry.
Next, run the program in a debugger. If you're using GDB:
$ gdb ./program


Nope, definitely not using GDB - this is a godawful Borland-compiled
GUI application that runs as a server on a remote machine, so GDB is
definitely out ;P

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #7

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

Similar topics

6
by: Eric Boutin | last post by:
Hi ! I have a strange problem with a std::ostringstream.. code : #include <sstream> /*...*/ std::ostringstream ss(); ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\"...
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...
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.
1
by: Voronkov Konstantin | last post by:
Hello all! std::ostringstream stream; stream << 8080; std::string str = stream.str(); // str == "8 080" The code shown above in mine big program result the str variable value to
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...
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...
2
by: mathieu | last post by:
Hi, I am playing with the following C++ piece of code (*). At least on my system debian/gcc 4.3 it looks like I am not writing out a floating point separator as a comma. what are the operation...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...
0
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,...

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.