How to input multiple number to stringstream in one line with C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

int main() {
    std::stringstream ss;
    
    ss << 34 << ' ' << 89 << ' ' << 9021;

    int a, b, c;
    
    ss >> a >> b >> c;

    std::cout << a << '\n';
    std::cout << b << '\n';
    std::cout << c << '\n';

    return 0;
}



/*
run:
 
34
89
9021
 
*/

 



answered Jan 14, 2021 by avibootz

Related questions

1 answer 132 views
2 answers 118 views
1 answer 98 views
1 answer 109 views
...