Vishva wrote: > > Dear C-Progs, > I'm confused with converting > LPCTSTR to char and char to LPCTSTR in Visual Studio 2005.. (C++) > Please tell me how to do this.. > Regards > Vish > > [Non-text portions of this message have been removed] > > Like Thomas said, an LPCTSTR is simply a pointer to a character (it can be a Unicode or ANSI character). Usually an LPCTSTR is going to pointer to the beginning of a string (the first character) that ends in a NULL character.
With that said, what you are really trying to do is convert between a single character and an array of characters (because a string is really just an array of characters). So, to convert a LPCTSTR type to a "char" you can simply dereference the pointer. // assuming it is ANSI LPCTSTR myStr = "Hello, World!"; char firstChar = *myStr; If you want to convert a single character to a string, you will need to allocate space for 2 characters: the character itself and the NULL character. // assuming it is ANSI LPCTSTR myStr = new char[2]; myStr[0] = 'a'; // the character myStr[1] = 0; // myStr is now the string "a". delete[] myStr; // free the memory used by it I hope that helped you out. ;)
