相关疑难解决方法(0)

将CString转换为std :: wstring

我怎样才能转换CStringstd::wstring

c++ string wstring

15
推荐指数
1
解决办法
3万
查看次数

DLL函数无法在VBA环境中工作,但在Excel VBA中工作

我在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)

c++ string excel vba

9
推荐指数
1
解决办法
487
查看次数

如何将CString转换为ofstream?

我有一些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)

有任何想法吗?谢谢!

c++

1
推荐指数
2
解决办法
7593
查看次数

标签 统计

c++ ×3

string ×2

excel ×1

vba ×1

wstring ×1