What I'm doing

Posted:
Aug 6, 2003 @ 4:36am
by mlepage
I installed STLport. You can use std::string OK, just not streams.
I use the <tchar.h> routines for text. That means using _sntprintf, _tcscpy, _tfscanf, and all those wonderfully named functions.
Just be smart about it. Write a small class that encapsulates your buffer of _TCHAR and the size of that buffer. (Hint: you can use std::vector because it is array compatible, see Meyer's Effective STL book.) Make that array one more than you need, and pre-terminate it with a null character in that last position. Then always use functions that take a size: snprintf instead of sprintf, "%32s" instead of "%s" in sscanf, strncpy instead of strcpy, etc.
If you really care about performance, you can make a templated version of that class with the size as a template parameter.
This approach is better than hardcoding _TCHAR mybuffer[128] and sprintf(mybuffer, 128, src) all through your code.

Posted:
Aug 6, 2003 @ 9:01am
by Pejo Software - Per
Just a little note in case anyone missed it:
std::string actually is defined as basic_string<char> ans wstring is defined as basic_string<wchar_t> so you can use basic_string<TCHAR> if you would like to work with TCHARs.