To get this code to compile I had to switch off pedantic-errors.
Apparently line 19 is not ISO C++.
Anyway your program fails at line 29 because string s is an empty string due to the perennial problem of using cin>> and then a getline().
cin>>n leaves a '\n' in the stream. getline places all chars in the stream before the '\n' into the string but there are no chars before the '\n' so the string is empty. getline then removes the '\n' from the stream. Now that the stream is empty the next getline will prompt the user for input.