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
1 Risposta
+ 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




