how to convert _T() to string and vice versa

how to convert _T() to string and vice versa

Page 1 of 1

2 Replies - 3446 Views - Last Post: 01 October 2010 - 10:12 AM Rate Topic: -----

#1 Hajidon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-October 10

how to convert _T() to string and vice versa

Posted 01 October 2010 - 09:00 AM

Hi,
I am trying to open a url when users click on the window.

ShellExecute(NULL,_T("open"),_T("http://www.google.com"),NULL,NULL, SW_SHOWNORMAL);

this works perfectly fine....
but what i am trying to do is, that i want to take input from the user and then append this input to the url...
basically

string fileName = "";
cout<<"enter file name: ";
cin>>fileName;

then i want to to append this file name to the url.
so i have tried this but not working.
string url = "http://www.google.com";
url = url + fileName;
and i have passed this to the above ShellExecute function.
ShellExecute(NULL,_T("open"),url,NULL,NULL, SW_SHOWNORMAL);


Can any one tell me why? and can any one tell me how to append values or convert string to _TCHAR * variable.
i know the url is suppose to be a _TCHAR type variable but i do not know how to convert it or append a string to it.

Regards,
Hajidon

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 01 October 2010 - 09:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to convert _T() to string and vice versa

#2 Coding in the name of   User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 293
  • Joined: 07-July 10

Re: how to convert _T() to string and vice versa

Posted 01 October 2010 - 09:08 AM

namespace std
{
    #ifdef _UNICODE
        typedef wstring tstring;
    #else
        typedef string tstring;
    #endif
};


(Assuming I understand correctly what a tchar is)
Using this you can call tstring::c_str() and get a constant string of tchars.
Or you could instantiate a template instance of basic_string for tchar.
Was This Post Helpful? 2
  • +
  • -

#3 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: how to convert _T() to string and vice versa

Posted 01 October 2010 - 10:12 AM

use url.c_str() rather than just url. IF you are using unicode then make sure that url is a wstring rather than just a string.

string::c_str()
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1