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 ;)

有帮助吗?

解决方案

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.

其他提示

Something like:

tstring yourString = _T("<your string here>");
captureNewPictures(yourVecPicsOld, yourString);

I don't have a Windows box to test this on, but

#include <string>
#include <iostream>

typedef char TCHAR;

typedef std::basic_string<TCHAR> tstring;

void somefunc(const tstring &dir)
{
    std::cout << dir << '\n';
}

int main()
{
    tstring foo = "hello world";
    somefunc(foo);

    somefunc("goodbye world");
}

works with GCC on my Mac OS X box. Does the above work for you? What is the exact error you get?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top