1

我有这个方法不是我的。这里有人给了我那个。

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

我试图初始化这个“dir”变量但没有成功。我是 C++ 的初学者,整天都在关注所有可能的文档(或几乎 :p )。有人可以解释一下如何将字符串值传递给“dir”,关于 tstring 定义为

typedef std::basic_string <TCHAR> tstring ;

PS:我看到我可以删除“dir&”的引用值,这是 after 的问题吗?PS2:如果您有一个很好的文档来解释字符串值及其相应的字段,那么这将非常棒;)

4

3 回答 3

3

tstring一直以这种方式输入,因此您将根据编译标志获得 ascii 或 Unicode 字符串。

要初始化字符串,请执行以下操作:

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

_T宏将通过L在 Unicode 构建中添加前缀将您的字符串转换为宽字符串,否则它将保留为常规 ascii 字符串。

于 2014-01-24T15:22:53.870 回答
1

就像是:

tstring yourString = _T("<your string here>");
captureNewPictures(yourVecPicsOld, yourString);
于 2014-01-24T15:22:56.517 回答
0

我没有一个 Windows 盒子来测试这个,但是

#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");
}

在我的 Mac OS X 机器上使用 GCC。以上对你有用吗?你得到的确切错误是什么?

于 2014-01-24T15:27:32.450 回答