I am working on a trivial problem, but I cant figure it out. The program should put out the part after "simon says" if the beginning of str1 is "simon says". if i run it like in the following code, it works, but if i enter the string over cin >> str1; myself, it doesnt. Does anybody have a tip for me? (and yes, this is a kattis problem)
int main() { string str1("simon says write a program"); //cin >> str1; string str2 ("simon says"); if (str1.compare(0,10,str2,0,10) == 0){ cout << str1.substr(11,str1.size()); } return 0; }
std::getline()cinreads strings word wise.>>extracts whitespace-separated tokens. This is not the construction you are looking for.cin << str1, you can see that the string contains only simon.