character array to string
This is probablly a real stupid question, but How do I convert a character array (char whatever[255]) into a string (like an LPCSTR or a char *whatever_string)?
Thanks :D
/\/\att
char *whatever_string = whatever;
Using just the name of an array gives you the address of the first element. Just remember that whatever_string only points to whatever, it doesn''t actually contain the data, and if something happens to whatever, whatever_string will potentially point to garbage.
I never use LPCSTR I assume its basically the same as a char*, but I really don''t know.
Marc Hanson
Programmer - Alter Echo
Outrage Games
Using just the name of an array gives you the address of the first element. Just remember that whatever_string only points to whatever, it doesn''t actually contain the data, and if something happens to whatever, whatever_string will potentially point to garbage.
I never use LPCSTR I assume its basically the same as a char*, but I really don''t know.
Marc Hanson
Programmer - Alter Echo
Outrage Games
It already is a string, at least in that format.
is the same as:
Although if possible you may want to consider std::string; it''s much easier to use in most cases, and can be easily converted to a char array by using string.c_str ().
char szName [] = "Melraidin";printf ( "%s\n", szName );
is the same as:
char *szName = "Melraidin";printf ( "%s\n", szName );
Although if possible you may want to consider std::string; it''s much easier to use in most cases, and can be easily converted to a char array by using string.c_str ().
I beleive that ''LPCSTR'' is the same thing as a ''const char*''.
It''s the type used by many functions taking a string argument. the ''const'' means that they can''t change it!
It''s the type used by many functions taking a string argument. the ''const'' means that they can''t change it!
it''s actually LPCTSTR
LP = Long pointer. A hold over from 16 bit Windows days
C = Const
TSTR = an array of TCHARs, basically TCHAR*
TCHAR =
basically, you use TSTR and CTSTR if you want your code to be portable between ASCII and UNICODE builds.
LP = Long pointer. A hold over from 16 bit Windows days
C = Const
TSTR = an array of TCHARs, basically TCHAR*
TCHAR =
#if defined(_UNICODE)typedef char TCHAR#elsetypedef wchar_t TCHAR#endif
basically, you use TSTR and CTSTR if you want your code to be portable between ASCII and UNICODE builds.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement