Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old May 26th, 2006, 05:15 PM
mlm
Guest
 
Posts: n/a
Default vector of stringstream*

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
Default 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
Default 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
Default 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





 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles