Simple question about strings

Hello, can someone please tell me what I need to do to make this work?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str;
	str.at(0) = 'A';
	str.at(1) = '1';
	cout << str;
        return 0;
	system("pause");
}


Thank you for your time :)
Last edited on
Line 6 creates an empty string.
Line 7 will fail because there is no existing character at index 0.
Line 8 will fail because there is no existing character at index 1.

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>

int main()
{
    std::string str;
    str += 'A' ;
    str += '1' ;
    std::cout << str ;
}
Thank you :)
Topic archived. No new replies allowed.