Jump to content
  • Advertisement
Sign in to follow this  
nick5454

Easy TCHAR ?

This topic is 4908 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

I have this char defined as so. TCHAR cString[64]; I want to place this into it using sprintf sprintf(cString, "String"); but I get an access violation. Please help Nick

Share this post


Link to post
Share on other sites
Advertisement
Well you are sure that code is causing the problem? I did the same

TCHAR cString[64];
sprintf(cString, "String");


In VS6 and VS7 with Win32 applications and it was fine. What else are you doing?

- Drew

Share this post


Link to post
Share on other sites
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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!