473,657 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stringstream strange output

consider the following piece of code, compiled with g++ 3.4 and
stlport 5.1 on Linux 64 bit (problem persists in 32 bit too)

std::stringstre am ss;
int ii = 123;
ss << "test1";
std::cout<<ss.s tr()<<std::endl ;
ss << ii << "test2";
std::cout << ss.str()<<std:: endl;

The output I'm getting is quite strange:
test1
test1test2

It like 'ii' is not printed. If I remove line #4, then all is fine and
I get "test1123te st2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22tes t2" as
expected.

drives me crazy. any idea what it can be?

Thanks,
Dmitry
Sep 23 '08 #1
2 2209
drusakov wrote:
consider the following piece of code, compiled with g++ 3.4 and
stlport 5.1 on Linux 64 bit (problem persists in 32 bit too)
#include <iomanip>
#include <iostream>
#include <sstream>

int main() {
std::stringstre am ss;
int ii = 123;
ss << "test1";
std::cout<<ss.s tr()<<std::endl ;
ss << ii << "test2";
std::cout << ss.str()<<std:: endl;
}
The output I'm getting is quite strange:
test1
test1test2

It like 'ii' is not printed. If I remove line #4, then all is fine and
I get "test1123te st2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22tes t2" as
expected.
Is it possible that memory is being corrupted elsewhere in your program?
What happens when you compile and run the above code as a stand-alone
program?
Sep 23 '08 #2
On Sep 23, 9:29 pm, drusakov <dmitry.rusa... @googlemail.com wrote:
consider the following piece of code, compiled with g++ 3.4
and stlport 5.1 on Linux 64 bit (problem persists in 32 bit
too)
Just a question: why? G++ has one of the better library
implementations around, the STL port is one of the worst. So
why use it with g++?
std::stringstre am ss;
int ii = 123;
ss << "test1";
std::cout<<ss.s tr()<<std::endl ;
ss << ii << "test2";
std::cout << ss.str()<<std:: endl;
The output I'm getting is quite strange:
test1
test1test2
It like 'ii' is not printed. If I remove line #4, then all is fine and
I get "test1123te st2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22tes t2" as
expected.
drives me crazy. any idea what it can be?
It would seem to be a bug in the STL. The above code works with
the default libraries with g++, Sun CC and VC++; I get the same
symptoms as you with Sun CC and the STL port, however.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 24 '08 #3

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

Similar topics

4
5804
by: David Johnstone | last post by:
Hi Group, I am using gcc 3.2.2 on linux 2.4.19-4GB (SuSe 8.2). I have a situation where I need to tie an ostringstream to an istringstream so I can write to one and read back what I wrote from the other. I had expected the code to look like: ostringstream* ostr_stdin = new ostringstream();
3
4214
by: David Olsson | last post by:
Hello! I have a little problem with one of the get methods of the stringstream class. Consider the code: #include <iostream> #include <sstream> #include <string> using namespace std;
4
4478
by: Field | last post by:
Hi, the following snippet shows once executed this output: 2 2 I'd have rather expected this output: 2 10
5
12053
by: Mr Fish | last post by:
Is it possible for me to record floats in a std::stringstream with 100% accuracy? If so how? Here's a little prog that demonstrates how the default ss loses accuracy //----------------------------------------------------------------------------- #include <sstream> #include <iostream> using namespace std;
10
2613
by: vigacmoe | last post by:
I was trying to cast some strings to integers with stringstream, then this strange problem poped up. Here is my test code: stringstream conv; string from; int to; from = "1"; conv << from;
1
2883
by: magix | last post by:
I got this reply in my previous post a month ago: May I know, how can I automatically create the folder if it doesn't exist ? In previous reply, it said: ------------------------- std::stringstream stream; stream << "C:\\Output\\Output.txt" << std::flush; std::ofstream SaveFile(stream.str().c_str()); The "C:\Output" must already exist?
2
21221
by: akitoto | last post by:
Hi there, I am using the std::stringstream to create a byte array in memory. But it is not working properly. Can anyone help me? Code: #include <vector> #include <sstream> #include <iostream.h>
0
1424
by: ziyanjoe | last post by:
Hi! I am writing a program for the robot that runs as a daemon on a linux machine. Since debug output cannot be seen on stdout, I want to create an iostream to handle all the output messages. However, I do not want to use a file or output to the clog since I want to achieve the debug message remotely through TCP connection. I've already built a TCP server for transmitting data, all i need is an "endless" stringstream. I tried to code this...
7
3599
by: Ziyan | last post by:
I am writing a C/C++ program that runs in background (Linux). Therefore, normally no output would be written into standard output. However, sometimes I want to have debug message collected and sent tho network to a client so that errors and debug messages can be displayed simultaneously anywhere. I tried to use a std::stringstream to do the job. I created the stringstream in main() and pass it as pointer into a few threads. Those threads...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
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
8503
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
8603
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
7320
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.