-1

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.

2
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by nated
0

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;
0

No actually ive tried different ways. Im VERY new to C++ and didnt understand what this function did.

1

That worked. I do really appreciate the time. Thank you.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.