If you use >> to read a string, it will only read up to the next space. So if you enter "my string", only the "my" will go into the string. The "string" will still be in the buffer, so the next time you try to read an integer, the read operation will fail because "string" is not an integer. Since you never check whether the read fails, this will cause an infinite loop.

If you want to read a whole line - not just up to the next space -, you'll have to use getline instead of >>.