0

Is it possible to store multiple int value as input in C++ without using array.

please explain with example if any know the answer

5th May 2018, 8:16 AM
Snehil Mahajan
Snehil Mahajan - avatar
1 Antwort
+ 3
Yes, it is possible, you can use vector of int in place of an array of int, here's a small example. #include <iostream> #include <vector> // Main procedure int main() { std::vector<int> intVector; int value; // input buffer // Read user input, add the value into the // vector while input is okay. while(std::cin >> value) { intVector.push_back(value); } // Display number of data stored in and // the vector's content to screen std::cout << "You entered " << intVector.size() << " integer(s):\n"; for(int data : intVector) { std::cout << data << " "; } return 0; } Check out the lesson about vector (SoloLearn app only, may not be available through web): https://www.sololearn.com/learn/261/?ref=app
10th May 2018, 6:10 PM
Ipang