class MyString
{
public:
MyString(const std::wstring& s2)
{
s = s2;
}
operator LPCWSTR() const
{
return s.c_str();
}
private:
std::wstring s;
};
int _tmain(int argc, _TCHAR* argv[])
{
MyString s = L"MyString";
CStringW cstring = L"CString";
wprintf(L"%s\n", (LPCWSTR)cstring); // Okay. Becase it has an operator LPCWSTR()
wprintf(L"%s\n", cstring); // Okay, fine. But how?
wprintf(L"%s\n", (LPCWSTR)s); // Okay. fine.
wprintf(L"%s\n", s); // Doesn't work. Why? It prints gabage string like "?."
return 0;
}
स्ट्रिंग% s प्रारूपित करने के लिए CString कैसे पारित किया जा सकता है?स्ट्रिंग% s प्रारूपित करने के लिए CString कैसे पारित किया जा सकता है?
वैसे, MSDN says (यह अजीब है) जैसा कि यहाँ दिखाया
एक चर तर्क समारोह
स्पष्ट रूप से एक LPCTSTR स्ट्रिंग के लिए cstring डाली में एक cstring वस्तु का उपयोग करने के लिए,:
CString kindOfFruit = "bananas";
int howmany = 25;
printf("You have %d %s\n", howmany, (LPCTSTR)kindOfFruit);
"काम नहीं करता" का क्या अर्थ है? संकलित नहीं करता है, अपेक्षित परिणाम नहीं दिखाता है ...? – MikMik
इसमें सी – Puppy
@MikMik के साथ बिल्कुल कुछ नहीं है: यह गैबेज स्ट्रिंग जैसे ** "?" ** ** – Benjamin