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

vector of stringstream*

mlm
Hi,

I believe that it should not be legal to create a vector (and array) of
stringstream since the copy constructor and assignment operators are
declared private. However, I don't understand why it shouldn't be
legal to create a vector (or array) or stringstream pointers. The
following code compiles and runs on g++, but seg faults while using the
Intel c++ compiler. Is this standard code? Which newsgroup (intel or
g++) needs to be consulted?
================================================== ===========
g++ -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
================================================== ============

Intel C++ compiler version 8.1
================================================== ============

#include <vector>
#include <sstream>
#include <iostream>

using namespace std;

int main()
{
int test1 = 100;
int test2 = 200;

vector<stringstream*> ssv;

for(int i=0; i<10; i++)
ssv.push_back(new stringstream);

cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;

for(int i=0; i<10; i++) {
*ssv[i] << "testing 1 2 3" << endl;
}

cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;

for(int i=0; i<10; i++) {
cout << ssv[i]->str() << endl;
cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;
}

return 0;
}

[ btw - while debugging this problem I noticed that local variables
declared at the top of method are being overwritten. If you use the
Intel compiler, you'll start to see that test1 and test2 will contain
garabage after a few iterations through the last for loop. And this is
another question - why would anything that is happening in the last for
loop cause _anything_ to be overwritten? ]

Thanks,
mlm

May 26 '06 #1
3 5264
mlm wrote:
I believe that it should not be legal to create a vector (and array)
of stringstream since the copy constructor and assignment operators
are declared private. However, I don't understand why it shouldn't be
legal to create a vector (or array) or stringstream pointers. The
following code compiles and runs on g++, but seg faults while using
the Intel c++ compiler. Is this standard code?
Yes, it's fine.
Which newsgroup
(intel or g++) needs to be consulted?
I don't know of Intel newsgroup, but I'd contact their tech support.
================================================== ===========
g++ -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
================================================== ============

Intel C++ compiler version 8.1
================================================== ============

#include <vector>
#include <sstream>
#include <iostream>

using namespace std;

int main()
{
int test1 = 100;
int test2 = 200;

vector<stringstream*> ssv;

for(int i=0; i<10; i++)
ssv.push_back(new stringstream);

cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;

for(int i=0; i<10; i++) {
*ssv[i] << "testing 1 2 3" << endl;
}

cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;

for(int i=0; i<10; i++) {
cout << ssv[i]->str() << endl;
cout << "test1: " << test1 << endl;
cout << "test2: " << test2 << endl;
}

return 0;
}

[ btw - while debugging this problem I noticed that local variables
declared at the top of method are being overwritten. If you use the
Intel compiler, you'll start to see that test1 and test2 will contain
garabage after a few iterations through the last for loop.
"After a few"? What does that mean? Are you saying it's arbitrary and
changes from one run to another? Pin-point the moment, then look where
it happens. Step into the library code if you can (should be able to).
And this
is another question - why would anything that is happening in the
last for loop cause _anything_ to be overwritten? ]


The code is fine. What you need to try is a different implemenation
of the Standard library than the one you already have (with Intel C++).

I just tried your code on Visual C++ v8 and it was fine.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 26 '06 #2
On Fri, 26 May 2006 12:18:25 -0400, "Victor Bazarov"
<v.********@comAcast.net> wrote:
mlm wrote:
I believe that it should not be legal to create a vector (and array)
of stringstream since the copy constructor and assignment operators
are declared private. However, I don't understand why it shouldn't be
legal to create a vector (or array) or stringstream pointers. The
following code compiles and runs on g++, but seg faults while using
the Intel c++ compiler. Is this standard code?


Yes, it's fine.


.... apart from the memory leaks (more precisely, object leaks).
May 26 '06 #3
"mlm" <mi*************@gmail.com> wrote in message news:11**********************@j73g2000cwa.googlegr oups.com...
Hi,

I believe that it should not be legal to create a vector (and array) of
stringstream since the copy constructor and assignment operators are
declared private.

[snip]

It is legal to create an array of stringstream, for instance,
stringstream ssa[10];

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

May 27 '06 #4

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

Similar topics

6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
5
by: krini_pop | last post by:
I have a string that is delimited by commas. I'm using strtok and putting the values in a vector. In some cases, I may have 2 commas side by side and therefore need it to insert a null value. Right...
3
by: Al | last post by:
What is the problem with this code? It always crashes at the 'push_back'. I found that thanks to debugging. Any Ideas? Other question: what is a faster way to convert a string to an integer? Is...
4
by: mathieu | last post by:
Hello, I am looking at the API of std::vector but I cannot find a way to specify explicitely the size of my std::vector. I would like to avoid vector::resize since it first initializes the...
6
by: Matt Chwastek | last post by:
Anyone who can help, I am curretnly attempting to write some code that will allow iteration using a vector<intfrom the highest possilbe degree of a combination of ones & zeros (111, 110, 101,...
4
by: stinos | last post by:
Hi All! suppose a class having a function for outputting data somehow, class X { template< class tType > void Output( const tType& arg ) { //default ToString handles integers/doubles
5
by: Fred | last post by:
Hi: I've got the following request: (suppose the required head file is included) vector<stringvec; // .......... // push some items into vec string str; // here I want to copy some range...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
5
by: yogi_bear_79 | last post by:
Distant learning student. My lab is to write a function to perform the addition of large integers, with no limit to the number of digits. (Also have to do a subtraction, division, and...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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...

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.