warning: ISO C++ forbids converting a string constant to ‘char*’
Is there an elegant way to initialize the C strings as C++ objects (string, vector, etc), then convert it back to C-String char* for the function? Note it needs to resolve back to a string pointer for the original function, which assume it cannot be modified. I created a fictitious existing_function() to indicate that the original C coded function needs a char* as an argument.
You are not supposed to modify the data of a string literal so C++ wants you to use const char*. If you use some legacy library that takes a non-const char* you will have to cast it, assuming you know that th funcon does not modify the string.
If you are not sure the function doesn't modify the string you might want to copy the string and pass the copy to the function instead, just to be safe.
Yes, this does look more thematic. I've never used char**, so now I know how it's used!
For now, I'm trying not to modify the functions. The function prototype in my case is: existing_function(char*), so I cannot modify it by adding char** or an int. Although I think it's a more elegant solution (and I think it may have been the original intent of the programmer, but I don't know). I may modify the function at some point but I'm reluctant to do that because I don't know how it will impact other calls to it. If I can get away with modifying the calling routine I'll leave it at that.