SigSev on Kattis

Hello,
my program runs fine on my PC, but the Kattis Judge tells me I have a sigsev.
Since the problem doesnt occurr on my PC, I don't know how to debug it. Just a little tip would be nice, thank you :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
using namespace std;

int main()
{
 int t;
 cin >> t;
 string str1;
 string str2 ("simon says");
 cin.ignore();

 for (int i=0; i<t; i++) {

  getline(cin,str1);
  cin.clear();
  if (str1.compare(0,10,str2,0,10) == 0){
   cout << str1.substr(11,str1.size()) << endl;
  }
  else cout << endl;

 }

 return 0;
}
line 18: If str1.size() < 12 the string will throw an exception. See:

http://www.cplusplus.com/reference/string/string/substr/

That will happen when someone enters "simon says" only.
String::compare

Let me hit Enter as input; the line has no characters and str1 becomes an empty string. No character at pos 0. Exception.

PS. You don't need subpos and sublen, because you do use the whole str2.
@coder777: thank you very much. i completely forgot to test that case!

@keskiverto: that doesnt happend to me. it prints an empty line like it should
Topic archived. No new replies allowed.