Search code examples
c++stringtcharstdstring

Init basic_string c++


I have this method which is not from me. Someone here gave me that.

void captureNewPictures(std::vector<Picture> &vecPicsOld, const tstring &dir)

And I've tried to init this "dir" variable without success. I'm beginner in C++ and watched out all the possible doc (or almost :p ) all day long. Could someone explain me how to pass a string value to "dir" please, regarding tstring is defined by

typedef std::basic_string <TCHAR> tstring ;

PS : I saw I could remove the reference value to "dir&", is this a problem for after ? PS2 : If you have a nice doc explaining string values and their corresponding fields this zould be very very great ;)


Solution

  • tstring has been types this way so that you'll get either ascii or Unicode strings depending on your compilation flags.

    To initialize the string do something like this:

    tstring greeting = _T("hello, world");
    

    The _T macro will convert your string to a wide string by prefixing it with L in a Unicode build, otherwise it will leave it as a regular ascii string.