How to fill stringstream with N copies of a string in C++

1 Answer

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

int main() {
    std::stringstream s;
    
    std::fill_n(std::ostream_iterator<std::string>(s), 3, "C++ Programming ");
    
    std::cout << s.str();;
}

 
 
/*
run:
    
C++ Programming C++ Programming C++ Programming 
             
*/

 



answered Oct 27, 2024 by avibootz
...