我在Excel中编写的DLL(c ++)中包含以下函数,我在Excel中调试过,并且运行得很好:
float _stdcall ReturnT(LPCSTR FileName)
{
// Extracts the generic language string from the (importing BSTR
// would import kanji or whatever) and converts it into a wstring
wstring str = CA2T(FileName);
// Sets the string to find as _t or _T followed by 2 or 3 digits and a subsequent _ or .
wregex ToFind(L"_[tT]\\d{2,3}(_|.)");
wsmatch TStr;
regex_search(str, TStr, ToFind); // Now the wsmatch variable contains all the info about the matching
wstring T = TStr.str(0).erase(0, 2); // …Run Code Online (Sandbox Code Playgroud) 我有一些CString变量,我希望输出到ofstream,但我似乎无法弄清楚如何这样做.这是一些示例代码.
我在VS 2005中启用了unicode
码:
ofstream ofile;
CString str = "some text";
ofile.open(filepath);
ofile << str; // doesn't work, gives me some hex value such as 00C8F1D8 instead
ofile << str.GetBuffer(str.GetLength()) << endl; // same as above
ofile << (LPCTSTR)str << endl; // same as above
// try copying CString to char array
char strary[64];
wcscpy_s(strary, str.GetBuffer()); // strary contents are correctly copied
ofile << strary << endl ; // same hex value problem again!
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!