How to replace all space characters (' ') with commas (,) in a string in c++.
This is what I tried.
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string a;
cin >> a;
replace(a.begin(), a.end(), ' ', ',');
cout << a << endl;
}
But when I enter something like this for example (stack overflow) it only returns (stack) for some reason.
Can someone correct the code please?