Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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);   
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #input #vector #size #unknown
ADD COMMENT
Topic
Name
4+2 =