1

Mostly, I'm trying to figure out how to terminate input of a specific type without having to write in some character. Eg

for (int I; std::cin >> I;)
{
    List.pushback(I);
}
double Value{};
std::cin >> Value;

If I want to terminate input for the first part, it seems std::cin keeps whatever I type to tell it to stop taking input, and directly throws it in Value without asking for a new input. Any way to fix that?

Edit for example clarification: Input:

12
34
3

some random character that stops input

23.5

Desired Result

List contains {12;34;3}

Value contains 23.5

Actual result

List contains {12;34;3}

Value contains some random character that stops input now converted

Marek R
  • 32,568
  • 6
  • 55
  • 140
John W.
  • 11
  • 2
  • What is the input and expected output? Please provide [mcve]. – Marek R Jul 05 '22 at 13:40
  • 2
    When `std::cin >> I` fails on "some random character" you need to clear cin's error state and consume the bad input. [Why would we call cin.clear() and cin.ignore() after reading input?](https://stackoverflow.com/a/5131654) – 001 Jul 05 '22 at 13:48

0 Answers0