As SiCrane is hinting at, with C++ always prefer std::string unless you have a real reason not to.
ya I do, like I said above I'm working with some really old code and it'll take too long to convert it all...
It'll take too long on the front end, but over the lifetime of the project, you'll probably waste more time fighting the chars.
If you have deadlines though, then there may not be enough time to meet the deadlines and refactor the project. Still, if you could schedule a time (three days or whatever you estimate it'll take) in the near future to refactor that aspect of the project, I think you'll feel alot better about it - and the code will certainly benefit from it.
But that's just my opinion!
Even if you can't use std::strings everywhere, you could still use them as a container-type for char arrays.
std::string cApp::ReturnString(char[30] &Temp)
{
std::string copy(temp, 30);
//...
return copy;
}
... later code...
std::string B;
std::string A = DoSomething(B[0], B.size());
(Assuming DoSomething() already exists as part of the old code-base and can't be changed. Otherwise, it'd be much better off just taking a std::string)
But everything new you write would be much better off as std::string.
If you absolutely have-to-have-to-have-to, you could do something like this:
struct CharArrayStruct30
{
char data[30]; //Horrible. *shudders*
};
But even this would be a step up:
struct RawStringStruct
{
char *data;
size_t size;
};
But std::strings constructors and functions are compatible with C-style raw strings, so you can migrate your codebase away slowly if you like.