I want to replace all the occurances of ' in a string to ^, but i saw string.replace is not the right function for me, do I need to write my own? It's boring.
+20
A:
You can use std::replace
from <algorithm>
instead of using string::replace
from <string>
Sample code
#include <iostream>
#include <algorithm>
int main()
{
std::string s = "I am a string";
std::replace(s.begin(),s.end(),' ',',');
std::cout<< s;
}
Output : I,am,a,string
Prasoon Saurav
2010-09-25 14:30:05
+1 for a straight-forward solution that makes my custom built STD::replace functions a waste.
Alexander Rafferty
2010-09-25 14:33:46