I am testing string output for a program in CodeBlocks. Here is the code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string entry = "";
while(entry!="x"){
cout<<"Enter: ";
cin>>entry;
cout<<entry.substr(0,1)<<endl;
}
return 0;
}
However prints the result as if it is delimitered by space and cout string "Enter" with wrong order as if it is bugged. What can be the reason and how can I solve this situation?
Output:
Enter: P q r
P
Enter: q
Enter: r
Enter: