Name: Anonymous 2012-02-15 13:28
I've avoided C++ for a long time but after a few months of using two high level languages (PHP and Javascript), I can't productively rely on C's strings any more. So I have a question. Is there any way of using C's string's with old C functions like
Note: I'm aware that
strcat() and strcpy(). Yeah, I'm aware of the C++ equivalents.
int main(void)
{
string firstName = "John";
string lastName = "Doe";
//This doesn't compile.
strcat(firstName, lastName.c_str());
//This compiles but doesn't work.
strcat(&firstName[0], lastName.c_str());
}Note: I'm aware that
firstName += lastName would work. Before migrating to C++ I have to find a way to get C++ strings to work with C functions. For example, in the Windows API there's a function called GetSystemDirectory(char * path, int size) which sets the variable 'path' with the path of the system directory. If possible I don't want to have to create C arrays to deal with functions like that. Thanks in advance.