this maybe to easy for some of you but i want to do transform this string:
to this...Quote:
this_is_a_string
i want the underscores to be replaced by spaces and vice versa... i want also to use transform stl (although lately stls hates me :mad: )Quote:
this is a string
for this to work but i seem not to do it quite right... i know that transform needs unary operators so i created one but it give me trouble because it needs a argument... here is my code
my unary_operators
and here is my transform...Code://unary functions.. for transforming space to _
struct trans_under : std::unary_function<char , char>
{
char operator () (char & in) const
{
if (in == '_'){
return ' ';
}else{
return in;
}
}
}tunder;
//unary functions.. for transforming _ to space
struct trans_space : std::unary_function<char , char>
{
char operator () (char & in) const
{
if (in == ' '){
return '_';
}else{
return in;
}
}
}tspace;
i look on bunch of stuffs in google and i find nothing with having your own unary operators.. it's always about lower case and upper case.Code:std::string str;
file >> str;
//doesn't work because tunder needs parameters??
std::transform(str.begin(), str.end(), str.begin(), tunder());
please help and more power!