Hi,
I want to implement the cstring class using wstring. but in assignement operator, I need to know how to add null while assigning some wchar_t type of data to the wstring. below is my code -
The second assignment operator is adding null after some garbage value copied into the wstring.
Also, see the code below-
Will this calculate the exact size required for both unix and windows?
Thanks,
I want to implement the cstring class using wstring. but in assignement operator, I need to know how to add null while assigning some wchar_t type of data to the wstring. below is my code -
Code:
class CString { public: wstring wStr; CString () {wStr = L"";} CString (wstring str) {wStr = str;} CString& operator =( const CString& stringSrc ); CString& operator =( wchar_t wcChar ); }; int main() { CString name = L"Vipul Bajaj"; CString name1 = L"Santosh Patil"; name1 = name; wchar_t aaa = L'Z'; name1 = aaa; return 0; } CString& CString::operator =( const CString& stringSrc ) { this->wStr.assign(stringSrc.wStr); return *this; } CString& CString::operator =( wchar_t wcChar ) { this->wStr.assign(&wcChar); int iLen = ((int) (sizeof (wcChar))) + 1; //Will this calculate the exact size required for both unix and windows this->wStr[iLen] = 0; return *this; }
Also, see the code below-
Code:
int iLen = ((int) (sizeof (wcChar))) + 1;
Thanks,
Comment