jeudi 29 avril 2021

How to insert spaces to string

I had multiple tries but failed all of them.

I am trying to write a function that sets space before first occurrence of > and another one after last occurrence of > how can I do that in C++11?

let's suppose my function is:

void add_space(string &e_cmd_line)
{
int f_ocu=e_cmd_line.find_first_of(">");
e_cmd_line.insert(f_ocu," ");
int l_ocu=e_cmd_line.find_last_of(">");
e_cmd_line.insert(l_ocu+1," ");

}

The main problem is that sometimes it returns bad signals, in case no > found and in e_cmd_line.insert(l_ocu+1," "); I can't know for sure there is l_ocu+1...

Aucun commentaire:

Enregistrer un commentaire