193030

Input sstream 2 arrays, stream.clear()!

Apr 2nd, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7. int array[1000]; // your heighest input range
  8. int array2[1000] = {};
  9. vector<int> numbers;
  10.  
  11. int main() {
  12.     string nums; // the numbers in the format "1 2 3 4 10 -20"
  13.     getline(cin,nums);
  14.  
  15.     stringstream stream(nums);
  16.     int i = 0;
  17.     int n;
  18.     while(stream >> n){
  19.         array[i++] = n;
  20.        // numbers.push_back(n);
  21.     }
  22.     getline(cin,nums);
  23.     stream.str(nums);
  24.     i = 0;
  25.     stream.clear();  // tova e reda, koito opravq neshtata
  26.     while(stream >> n){
  27.         array2[i++] = n;
  28.        // numbers.push_back(n);
  29.     }
  30.  
  31.     for(int i = 0; i<=10; i++)
  32.     {
  33.         cout << array[i] << " " << array2[i]<<endl;
  34.     }
  35.     // The number of integers in array is i. You can do anything with this number.
  36.     // numbers contains the input numbers.
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment