Search
 
SCRIPT & CODE EXAMPLE
 

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);   
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ modulo positive 
Cpp :: convert letters to uppercase in c++ 
Cpp :: stack implementation using class in c++ 
Cpp :: c++ double is nan 
Cpp :: how to find last character of string in c++ 
Cpp :: How to create files in C++ 
Cpp :: quick sort c+++ 
Cpp :: power of two c++ 
Cpp :: how to convert ascii to char in cpp 
Cpp :: number of digits in int c++ 
Cpp :: char to integer c++ 
Cpp :: arduino xor checksum 
Cpp :: Find minimum maximum element CPP 
Cpp :: new c++ 
Cpp :: c define 
Cpp :: intersection.cpp 
Cpp :: struct c++ 
Cpp :: login system with c++ 
Cpp :: gcc suppress warning inline 
Cpp :: c++ switch statement 
Cpp :: count number of prime numbers in a given range in c 
Cpp :: How to turn an integer variable into a char c++ 
Cpp :: read string with spaces in c++ 
Cpp :: Finding square root without using sqrt function? 
Cpp :: c++ variable types 
Cpp :: c++ loop trhought object 
Cpp :: QVariant to int 
Cpp :: c++ if statement 
Cpp :: c++ set intersection 
Cpp :: Array declaration by specifying the size in C++ 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =