Connecting Tech Pros Worldwide Help | Site Map

vector of stringstream*

  #1  
Old May 26th, 2006, 05:15 PM
mlm
Guest
 
Posts: n/a
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

  #2  
Old May 26th, 2006, 05:25 PM
Victor Bazarov
Guest
 
Posts: n/a

re: vector of stringstream*


mlm wrote:[color=blue]
> 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?[/color]

Yes, it's fine.
[color=blue]
> Which newsgroup
> (intel or g++) needs to be consulted?[/color]

I don't know of Intel newsgroup, but I'd contact their tech support.
[color=blue]
> ================================================== ===========
> 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.[/color]

"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).
[color=blue]
> And this
> is another question - why would anything that is happening in the
> last for loop cause _anything_ to be overwritten? ][/color]

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


  #3  
Old May 26th, 2006, 05:35 PM
Roland Pibinger
Guest
 
Posts: n/a

re: vector of stringstream*


On Fri, 26 May 2006 12:18:25 -0400, "Victor Bazarov"
<v.Abazarov@comAcast.net> wrote:[color=blue]
>mlm wrote:[color=green]
>> 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?[/color]
>
>Yes, it's fine.[/color]

.... apart from the memory leaks (more precisely, object leaks).
  #4  
Old May 27th, 2006, 01:15 PM
Alex Vinokur
Guest
 
Posts: n/a

re: vector of stringstream*


"mlm" <michael.l.mason@gmail.com> wrote in message news:1148659640.828250.302720@j73g2000cwa.googlegr oups.com...[color=blue]
> 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.[/color]
[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





Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading/Writing Vector of Structs to/from Tab Delimited File jwwicks answers 1 October 19th, 2007 10:46 PM
using sstream to read a vector<string> arnuld answers 6 September 16th, 2007 06:35 AM
vectorstream analogous to std::stringstream Marcin Kalicinski answers 5 February 8th, 2006 10:35 AM
vector 'push_back' problem Al answers 3 December 26th, 2005 09:15 AM