2012-08-01 60 views
1

我在说的CString类型是microsoft's如何摆脱C++中CString中的字符串

我试过两种方法;使用删除()和替换()在MSDN网站上找到的功能,和Visual C

方法1)++说Error:argument of type "const char*" is incompatible with argument of type "wchar_t"

特别是我的代码是:

#include <cstring> 

CString sTmp= sBody.Mid(nOffset); 
CString sFooter= L"https://" + sTmp.Mid(0, nEnd); 
sFooter.Remove("amp;"); 

而且我不希望一次删除一个字符,因为它会删除其他'a'。

出于某种原因,当我转换sFooter到的std :: string,随机的“放大器;” S似乎不应该出现在字符串中...

我转换sFooter到一个std: :字符串是这样的:

CT2CA p (sFooter); 
string str (p); 

方法2)转换CString的到的std :: string,然后使用擦除()和remove()摆脱的 “放大器;” S

#include <string> 
#include <algorithm> 

sFooter2.erase(std::remove(sFooter2.begin(), sFooter2.end(), "amp;"), sFooter2.end()); 

但Visual Studio的输出显示了这个:http://pastebin.com/s6tXQ48N

回答

3

尝试使用更换。

sFooter.Replace(_T("&amp;"), _T(""));

+0

它的工作原理的“wchar_t的”'的说法不兼容!谢谢你,先生 – minusatwelfth 2012-08-01 06:42:52

0

错误信息非常清楚。而不是使用常规字符串,你需要使用宽字符串。

sFooter.Remove(L"amp;"); 

另外according to the documentationRemove方法只接受单个字符。您需要找到另一种方法来删除整个子字符串。

+0

当我尝试,有下升的红线,说'错误:类型的参数“常量为wchar_t *”是类型 – minusatwelfth 2012-08-01 02:42:00