I will tell you one thing that does not immediately match your code, not your specific problem, but nonetheless hairy.
I assume your mainMenu() function calls this. In this case, you are misunderstood that:
if (str == "911")
will return to your menu. It will not be done. What he will do is call your main menu code again and, ultimately, you will run out of stack space.
I suspect you should loop in mainMenu() , and this code should just use return; , and not recursively call mainMenu() .
This and the fact that I think you should compare MessageToAdd with "911" , not str .
Another thing I would like to do is put the debug temporary code in:
cout << "DEBUG A\n"; i=0; while (i < 10) { cout << "DEBUG B " << i << "\n"; if (myMessages[i].empty()) { cout << "DEBUG C\n"; myMessages[i]=MessageToAdd; break; } else { i++; cout << "DEBUG D " << i << "\n"; } cout << "DEBUG E\n"; } cout << "DEBUG F\n";
and see what is printed. Of course, you can track the execution in the debugger, but it will require you to do the work. If you just post the output (the first 100 lines, if it's huge), then we can probably tell you what's wrong.
Actually, I think your problem is cin.ignore . When I run my code, nothing works, neither Test nor Test Test Test . This is because it ignores the first 1080 characters I'm trying to enter. The proof can be seen when you modify these statements:
cin.ignore(1); getline (cin,MessageToAdd); cout << MessageToAdd << "\n";
and you get est output when you type Test .
Take out the ignore line and try again. I am not sure about this, since you seem to indicate that Test working, but I do not see this being correct.
So here is what you need to do (minimum):
- completely get rid of
cin.ignore . - use
return , not mainMenu() . - use
if (MessageToAdd == "911") instead of if (str == "911") . - let us know how this happens.