473,385 Members | 1,742 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,385 software developers and data experts.

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::stringstream ss;
int ii = 123;
ss << "test1";
std::cout<<ss.str()<<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 "test1123test2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22test2" as
expected.

drives me crazy. any idea what it can be?

Thanks,
Dmitry
Sep 23 '08 #1
2 2199
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::stringstream ss;
int ii = 123;
ss << "test1";
std::cout<<ss.str()<<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 "test1123test2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22test2" 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.comwrote:
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::stringstream ss;
int ii = 123;
ss << "test1";
std::cout<<ss.str()<<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 "test1123test2" also if to replace 'ii' in line 5 with some
string, like "test22", you'll get last line "test1test22test2" 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 objektorientierter Datenverarbeitung
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
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...
3
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
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
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 ...
10
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
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: -------------------------...
2
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...
0
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....
7
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.