c++ - Get only the first value from std::cin -


when reading input std::cin want allow single numeric entry. given code

float n = 0; std::cin >> n; 

how identify case user input 1 2 3?

use getline , istringstream , run while loop count number of integers entered:

string line; getline(cin, line); int x, cnt = 0; istringstream iss(line); while(iss >> x){     cnt++; } 

cnt 3 1 2 3.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -