Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reading a line of integers from command line
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
vector<int> vector_of_int;
string str;
printf("Insert your numbers separated by space: ");
getline(std::cin, str);
istringstream sstr(str);
int n;
while (sstr >> n)
vector_of_int.push_back(n);
int max = vector_of_int[0];
int min = vector_of_int[0];
printf("Input Numbers: [");
for (int i = 0; i < vector_of_int.size(); i++){
printf(" %d", vector_of_int[i]);
if (vector_of_int[i] < min)
min = vector_of_int[i];
if (vector_of_int[i] > max)
max = vector_of_int[i];
}
printf(" ]\n\nMax: %d Min: %d\n", max, min);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment