Re: Formating a string using sprintf and showing it in MessageBox!
Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance
Hi Mihai!
__stprintf(msg, _T("My name is: %s "), (LPCTSTR) my_name);
>
But he is not right in double-underscore in __stprintf :-)
Correct that, and you have a running thing.
Upps... it was a copy-and-past error...
But to be even better, he should use "_sntprintf" instead of "_stprintf"!
<code>
ifdef _UNICODE
#define tstring std::wstring
#else
#define tstring std::string
#endif
TCHAR msg[120];
tstring my_name = _T("John");
_sntprintf(msg, 120, _T("My name is: %s "), (LPCTSTR) my_name);
MessageBox(NULL, msg, NULL, MB_OK);
</code>
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
.
Relevant Pages
- Re: Formating a string using sprintf and showing it in MessageBox!
... TCHAR msg; ... MessageBox(NULL, msg, NULL, MB_OK);} ... (microsoft.public.dotnet.languages.vc) - Re: Copying a CString to a std::string
... tstrings to account for Unicode vs. ANSI with something like: ... typedef wstring tstring; ... typedef wstringstream tstringstream; ... to namespace std or namespaces within namespace std unless otherwise ... (microsoft.public.vc.mfc) - Re: Copying a CString to a std::string
... tstrings to account for Unicode vs. ANSI with something like: ... typedef wstring tstring; ... typedef wstringstream tstringstream; ... it's undefined behaviour to extend namespace std. ... (microsoft.public.vc.mfc) - Re: Copying a CString to a std::string
... tstrings to account for Unicode vs. ANSI with something like: ... typedef wstring tstring; ... typedef wstringstream tstringstream; ... (microsoft.public.vc.mfc) - Re: Copying a CString to a std::string
... tstrings to account for Unicode vs. ANSI with something like: ... typedef wstring tstring; ... typedef wstringstream tstringstream; ... (microsoft.public.vc.mfc) |
|