我有一个接受LPCTSTR的向量,并通过引用wstring(ws1)插入了一个值。问题是每当ws1改变其值时,先前插入的值也会改变向量。任何建议如何在插入vector后删除对ws1的引用?
const char* attributeoffile = file->Attribute("Method");
vecFileConsolidateParams.push_back(FILECONSOLIDATEPARAMS());
size_t size = strlen(attributeoffile)+1;
std::wstring ws1;
ws1.resize(size, L'\0');
#pragma warning (disable : 4996 )
std::mbstowcs(&ws1[0], attributeoffile, size);
vecFileConsolidateParams[count].filemethod = &ws1[0] ;
答案 0 :(得分:-1)
修好了。使用了new运算符,wmemset和wmemcpy。
TCHAR *tc0 = new TCHAR[size0];
tc0[size0] = { L'\0' };
wmemcpy(tc0, &ws0[0], size0);
.
.
.
vecFileConsolidateParams[count].filename = tc0;
delete [] tc0;