I'm assuming that a tstring is simply a basic_string<TCHAR>.
If that's the case, then you should wrap all your string literals using the _T() or _TEXT macro. Otherwise, if you never plan on compiling you code for UNICODE target then don't bother with tstring, just use string.
That aside, printf() style formatting is done in C++ using streams, like cin, cout, fstream's etc...
basic_string<> can have I/O streams as well:
* basic_istringstream<>
* basic_ostringstream<>
* basic_stringstream<>
These have cooresponding typedef's just like basic_string<> does:
* stringstream (for type char)
* wstringstream (for type wchar_t)
* tstringstream (don't know if this is typedef'd for you or not)
And there are input only and output only versions of each of these like istringstream and ostringstream.
Here is some code that defines the tstring and tostringstream types and uses them.
Code:
//#define _UNICODE // enable to test as a UNICODE build
#include <tchar.h>
#include <sstream>
#include <iostream>
#include <iomanip>
using namespace std;
// typedef a TCHAR string and ostringstream types
typedef basic_string<TCHAR,
char_traits<TCHAR>,
allocator<TCHAR> > tstring;
typedef basic_ostringstream<TCHAR,
char_traits<TCHAR>,
allocator<TCHAR> > tostringstream;
// define "tcout" to be either cout or wcout depending
// on the true type of TCHAR
#ifdef _UNICODE
#define tcout wcout
#else
#define tcout cout
#endif
int main()
{
tostringstream ts_out;
ts_out << _T("double val = ") << 1234.5678 << endl
<< _T("long val = ") << 69L << endl
<< _T("long val in hex = 0x") << hex << 105L << dec << endl;
tstring results = ts_out.str();
tcout << results;
return 0;
}//main
Your alternative is to use _stprintf() on a TCHAR buffer and assign that to your tstring.
gg