If I have my own SString class in c++ and I want to be able to do this:
SString x("text"); LPCSTR p = (LPCSTR)x; cout<<p; How do I do it?
Create conversion operator to LPCSTR in your class SString. If you can use C++11 this operator should be explicit.
operator LPCSTR() const { /*return data*/ }; Also you can create some function like (i think this variant is better, than conversion operator)
LPCSTR asLPCSTR() const { /*return data*/ };
static_cast<LPCTSTR>(x);always prefer c++ style casts over c style casts; they're easier to spot, and they're more restricted in what they can do, so there's less chance of errors creeping in by casting!std::ostream operator<<(std::ostream&, const SString&)instead