# include <iostream>
# include <algorithm>
# include <string>
usingnamespace std ;
int main ()
{
string name ;
name [5] = 'e' ; // initialize the 5th element of the string
for (int i=0 ; i<5 ; i++)
{
name += ' '; //putting spaces from element 0 to 4 in the string
}
// print the string till the 5th element
for (int i=0 ; i<6 ; i++)
{
cout << name [i] ;
}
system ("Pause");
}
why is this code is not running ......string out of range
# include <iostream>
# include <algorithm>
# include <string>
usingnamespace std ;
int main ()
{
string name ;
for (int i=0 ; i<5 ; i++)
{
name += ' ';
}
name [5] = 'e' ; // Here is the chanage
for (int i=0 ; i<6 ; i++)
{
cout << name [i] ;
}
system ("Pause");
}
# include <iostream>
# include <algorithm>
# include <string>
usingnamespace std ;
int main ()
{
string name ;
name [5] = 'e' ; // initialize the 5th element of the string
for (int i=0 ; i<5 ; i++)
{
name += ' '; //putting spaces from element 0 to 4 in the string
}
// print the string till the 5th element
for (int i=0 ; i<6 ; i++)
{
cout << name [i] ;
}
system ("Pause");
}