Reputation: 232
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 ;)
Upvotes: 1
Views: 848
Reputation: 517
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?
Upvotes: 0
Reputation: 27577
Something like:
tstring yourString = _T("<your string here>");
captureNewPictures(yourVecPicsOld, yourString);
Upvotes: 1
Reputation: 62492
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.
Upvotes: 3