Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

input numbers to int c++

int main() {
        std::string str;
        //read whole line into str
        std::getline(std::cin, str);
        std::stringstream ss(str);
        //create a istream_iterator from the stringstream
        // Note the <int> because you want to read them
        //as integers. If you want them as strings use <std::string>
        auto start = std::istream_iterator<int>{ ss };
        //create an empty istream_iterator to denote the end
        auto end= std::istream_iterator<int>{};
        //create a vector from the range: start->end
        std::vector<int> input(start, end);
    
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #input #numbers #int
ADD COMMENT
Topic
Name
1+3 =