How to convert _TCHAR * to string?  
Author Message
wamax





PostPosted: Wed Oct 18 15:10:38 CDT 2006 Top

Visual Studio C++ >> How to convert _TCHAR * to string? I need to check command line parameter
if (argv[1] == option) .... // option is a string variable

And argv is defined as _TCHAR* argv[] by MSVS wizard.
The code don't work and it's very hard to convert argv[1] to string.

Visual Studio339  
 
 
Doug





PostPosted: Wed Oct 18 15:10:38 CDT 2006 Top

Visual Studio C++ >> How to convert _TCHAR * to string? On Wed, 18 Oct 2006 11:48:01 -0700, nkw <EMail@HideDomain.com>
wrote:

>I need to check command line parameter
>if (argv[1] == option) .... // option is a string variable
>
>And argv is defined as _TCHAR* argv[] by MSVS wizard.
>The code don't work and it's very hard to convert argv[1] to string.

What's the type of "option"? I'm going to assume it's std::string, and if
so, the variable "option" needs to be a TCHAR-based string, e.g. a tstring
defined as below:

typedef std::basic_string<TCHAR> tstring;

--
Doug Harrison
Visual C++ MVP
 
 
Ulrich





PostPosted: Thu Oct 19 02:15:53 CDT 2006 Top

Visual Studio C++ >> How to convert _TCHAR * to string? nkw wrote:
> I need to check command line parameter
> if (argv[1] == option) .... // option is a string variable
>
> And argv is defined as _TCHAR* argv[] by MSVS wizard.
> The code don't work and it's very hard to convert argv[1] to string.

You can replace the non-standard tmain(int, TCHAR**) with a standard
main(int, char**) and then it works. Another alternative is to use a
TCHAR-based string all the way through. Yet another one is to convert
strings accordingly and compare then.

Uli