This's got probably an easy answer but it's been puzzling me a few hours already.
The code below declares a string object and fills it character by character. I can print every single character (line 16) but I can't print the string as a whole (line 19).
Could anybody tell me why is that so and how to fix it, please?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
cout << "String a is: " << a << endl; //Nothing expected, fine
char tmp= 100;
for (int i=0; i<10; i++)
{
a[i]= tmp;
tmp++;
}
for (int i=0; i<10; i++)
cout << a[i];
cout << "\na: " << a << endl;
return 0;
}