Code:
char String::c_str()
{
char* cs;
cs = new char[length+1];
strcpy(cs,first);
return cs;
}
There's your invalid conversion.
The idea that a c_str function should allocate an unmanaged string buffer doesn't look good, though.
More commonly this should look like:
Code:
const char* String::c_str() const
{
return first;
}
All the const's so that the user wouldn't be able to mess around with the internal buffer.
If they now want to store that into a dynamically allocated char array, that's entirely up to them to do in the calling code.
Otherwise, most often you'd use the c_str method like this:
Code:
String s("filename");
std::ofstream fout(s.c_str());
When done your way, that would be a memory leak.