Sign in to follow this  

Easy TCHAR ?

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you're using a char*, you need to use sprintf.
If you're using a wchar_t*, you need to use wsprintf.
If you're using a TCHAR*, I think you'll need to use _tsprintf.

_tsprintf(cString, _T("String"));

Share this post


Link to post
Share on other sites
Quote:
Original post by nick5454
Thanks for helping. It turns out it was in another class that error was populating.

Thanks for the description. These too many string rules.

Nick


Char-star manipulation got you down? Plagued by memory management, buffer overruns and arcane incantations for string manipulation? Confused by the use of a sequence of numeric values ending in zero to represent text? Tired of having blind faith that all those values beyond the pointer are actually there when you only point to the first one?

There is a better way!

(Edit: just so you don't miss it: )
Quote:
std::string doc
The basic_string class is parameterized by character type, and by that type's Character Traits. Most of the time, however, there is no need to use the basic_string template directly. The types string and wstring are typedefs for, respectively, basic_string<char> and basic_string<wchar_t>.


So if you want to stick with TCHAR as your character "model" (this is AFAIK a typedef for either char or wchar_t), you can just add another typedef in order to get the appropriate string type in your project:

namespace std {
typedef basic_string<TCHAR> tstring;
}

std::tstring myStringThatMightPossiblyUseUnicodeButIWillNotReallyKnowUntilCompileTime;


[Edited by - Zahlman on February 12, 2005 6:04:59 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
... [std::string goodness] ...



#include <iostream>
#include <string>

using namespace std;

int main(){
string strGoodness = "std::string is your friend!";
cout << strGoodness;
cin.get();
return 0;
}

Share this post


Link to post
Share on other sites

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this