It is necessary several times to enter and display a string that contains spaces. How many times to enter-output is at the discretion of the user. Tried it, but not working.
#include <conio.h> #include <string> #include <iostream> using namespace std; int main () { string str; int i = 0; do { cout << "str:"; getline(cin, str, '\n'); cout << "str:" << str << endl; cout << "repeat (1-yes/0-no)"; cin >> i; } while (i == 1); getch(); return 0; }
The program is compiled and the cycle repeats, but when I assign the value i to variable 1, no further line is entered. It looks like this:
Input text: this is text Text: this is text repeat (1/0):1 Input text: Text repeat (1/0):1 Input text: Text repeat (1/0):1
And so on until I get out of the cycle. Tell me what the error is and how to fix it.