Skip to content

Instantly share code, notes, and snippets.

Created February 25, 2016 11:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save udaya1223/67238446011659d166a8 to your computer and use it in GitHub Desktop.
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)
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