fork(1) download
  1. #include <string>
  2. #include <sstream>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int *array;
  10. string line;
  11. getline(cin,line); //read the entire line
  12. int size;
  13. istringstream iss(line);
  14. if (!(iss >> size))
  15. {
  16. //error, user did not input a proper size
  17. }
  18. else
  19. {
  20. //be sure to check that size > 0
  21. array = new int[size];
  22. for (int count = 0 ; count < size ; count++)
  23. {
  24. //we put each input in the array
  25. if (!(iss >> array[count]))
  26. {
  27. //this input was not an integer
  28. }
  29. }
  30. cout << "Array contains:" << endl;
  31. for (int i = 0 ; i < size ; i++)
  32. {
  33. cout << array[i] << ' ' << flush;
  34. }
  35. delete[] (array);
  36. }
  37. }
Success #stdin #stdout 0s 3032KB
stdin
6 1 2 3 4 5 6
stdout
Array contains:
1 2 3 4 5 6