My program crashes upon running it.

#include <iostream>
#include <string>
using namespace std;

int main() {
int n=2;
string A[n];
n++;
cin>>A[n-1];
}

This is a basic code, not the whole program, just the part that's not working.

Help please!

Thank you in advance!
Hello. Your problem is that you are going out of bounds with that array.
n = 2, so the string array 'A' has 2 strings. Position 0, and position 1. Later you access n-1, which ends up being 3 - 1 which = 2. There is no position 2 in the array, so it crashes.
Hint: '0' is the first element in an array.
Oh my god, I can't believe that I missed that, thx a lot guys, really thank you :)
Topic archived. No new replies allowed.