Answers for "how to input a vector when size is unknown"

C++
0

how to input a vector when size is unknown

#include <string>
#include <vector>
#include <sstream>
#include <string>

int main()
{
    std::vector<int> vec;
    std::string buffer;
    int data;
    std::getline(std::cin, buffer);
    std::istringstream iss(buffer);
    while (iss >> data)
          vec.push_back(data);
    //foo(vec);   
}
Posted by: Guest on July-30-2020

Code answers related to "how to input a vector when size is unknown"

Browse Popular Code Answers by Language