The goal is to replace Invalid_Enum with int. The approach.
I'm not sure there's a more efficient way to do this? I suspect one way to do this is to write the replace function to take as arguments the Source string, the Replacement strings, the start and end character (or start and end string) .Code:# include <string> # include <iostream> void Replace( std::string& Source, const std::string& Replacement) { std::string::size_type Pos = 0; Pos = Source.find( '(' ); Pos++; std::string::size_type Pos2 = 0; Pos2 = Source.find ( "Enum" , Pos ) ; Pos2 += 3; Source.replace ( Pos, Pos2, Replacement ); } int main() { std::string test ( "(Invalid_Enum e )" ) Replace ( test, " int" ) ; std::cout << test << std::endl; std::cin.get(); }




Reply With Quote