Ok im passing in a string and i cant get it to convert to a char array. Ive tried this so far.
int MyString::find(const std::string& str)
{
char* newString = str;
return 1;
}
Im pretty lost here.
Ok im passing in a string and i cant get it to convert to a char array. Ive tried this so far.
int MyString::find(const std::string& str)
{
char* newString = str;
return 1;
}
Im pretty lost here.
You clearly didn't search hard.
str.c_str() // returns a constant pointer to its characters
If you want to 'copy' the string into a character buffer, you have to do something along the lines of:
char *newStr = new char[str.length()+1];
strcpy( newStr, str.c_str() );
// Deal with newStr
delete[] newStr;
No actually ive tried different ways. Im VERY new to C++ and didnt understand what this function did.
That worked. I do really appreciate the time. Thank you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.