i press one the menu i cants input a line it just ,outputs "enter: "
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <string>
#include <list>
#include <iterator>
using namespace std;
const int NUM_LINES = 5;
int main()
{
string input;
list <string> myList(NUM_LINES);
list <string>::iterator it = myList.begin();
int i = 1;
int repeat;
do{
if (myList.size() > 5)
{
cout << "List is full. Cannot add more to list, please delete a line." << endl;
}
else if (myList.empty())
{
cout << "List is empty. Cannot delete lines from list, please add a line." << endl;
}
else if(repeat == 1)
{
for(int inx = 0;inx < NUM_LINES; inx++)
{
cout << "Enter a line " << endl;
getline(cin, input);
myList.push_back(input);
cout << endl;
}
}
else
{
repeat = 0;
}
cout << "1 to INSERT, 0 to quit: ";
cin >> repeat;
}while(repeat <= 1 || repeat >= 5);
return 0;
}
|
Last edited on
repeat is user input
the do while loop checks if repeat is one of the numbers
why is my "Enter a line " print twice?
why is my "Enter a line " print twice? |
the new-line character is left in the input stream after the std::cin on line 44, stick this in after that:
std::cin.ignore();
Last edited on