I am attempting to print a string to the console with this code and I'm using subscript operators to change characters at specific indices, when I run my code this way, it prints an empty string several times.
char last = 'c';
string str = "";
for (int i = 97; i <= (int)last; i++)
{
str[0] = (char)i;
for (int j = 97; j <= (int)last; j++)
{
str[1] = (char)j;
cout << str;
cout << endl;
}
}
However, when I write my code this way, it prints out the characters I want to see.
char last = 'c';
string str;
for (int i = 97; i <= (int)last; i++)
{
str[0] = (char)i;
for (int j = 97; j <= (int)last; j++)
{
str[1] = (char)j;
cout << str[0] << str[1];
cout << endl;
}
}
Is there anyway to get the characters I am manipulating to be saved into the string I initialized? Thank you!!