How to convert int vector to string in C++

1 Answer

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

int main(void)
{
	std::vector<int> v = {4, 6, 8, 2, 1, 10, 3, 5, 13};
	
	std::stringstream ss;
    copy(v.begin(), v.end(), std::ostream_iterator<int>(ss, " "));
    
    std::string str = ss.str();
	
	std::cout << str;
}




/*
run:

4 6 8 2 1 10 3 5 13 

*/

 



answered Oct 15, 2022 by avibootz

Related questions

1 answer 99 views
1 answer 114 views
114 views asked Sep 22, 2022 by avibootz
1 answer 111 views
2 answers 190 views
1 answer 194 views
1 answer 136 views
136 views asked Feb 17, 2019 by avibootz
...