Created
February 25, 2016 11:30
-
-
Save udaya1223/67238446011659d166a8 to your computer and use it in GitHub Desktop.
Reading a line of integers from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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