Urgent 'String size limitation'

masaoud@pspl.co.in masaoud@pspl.co.in
Mon Feb 4 09:32:00 GMT 2002


Hi,

    I am compiling a C++ (STL) program on the following 
configuration :
----------------------------------
Linux version 2.4.17
gcc version 2.96 20000731
Red Hat Linux 7.1 2.96-81
compat-libstdc++-6.2-2.9.0.14
libstdc++-devel-2.96-81
libstdc++-2.96-81
----------------------------------

I have enclosed below a sample c++ program that throws a 
segmentation fault.    Why does this code do so ? 
Is there some bug in the STL 'string' class ?

----------------------------------------------------
#include <string>
#include <iostream>
using namespace std;
 
#define BIGBLOCK 10000
 
int main( void )
{
    string finalstr = "";
    for( int i = 0; i <= BIGBLOCK; i++ )
    {
        finalstr[ i ] = '1';
    }
    cout << "Size = " << finalstr.size( ) << endl;
}
----------------------------------------------------

Is there a solution to the above problem ?


Thanks in advance,

Regards
Masaoud.



More information about the Libstdc++ mailing list