How to replace spaces with colons in vector using C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<char> vec{ ' ', 'c', '+', ' ', '+', ' ' };

	replace_copy(vec.begin(), vec.end(), vec.begin(), ' ', ':');

	for (int i = 0; i < vec.size(); i++)
		cout << vec[i];
	
	cout << endl;

	return 0;
}


/*
run:

:c+:+:

*/

 



answered May 19, 2018 by avibootz
...