小编min*_*fth的帖子

如何在C++中摆脱CString中的字符串

我所说的 CString 类型是微软的.

我尝试了两种方法;

方法 1) 使用在 msdn 网站上找到的 Remove() 和 Replace() 函数,Visual c++ 说 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;");
Run Code Online (Sandbox Code Playgroud)

而且我不想一次删除一个字符,因为它会去掉其他的 'a'。

出于某种原因,当我将 sFooter 转换为 std::string 时,随机的“amp;”出现在不应该存在的字符串中......

我正在将 sFooter 转换为 std::string ,如下所示:

CT2CA p (sFooter);
string str (p);
Run Code Online (Sandbox Code Playgroud)

方法2)将CString转换为std::string,然后使用erase()和remove()去掉“amp;”

#include <string>
#include <algorithm>

sFooter2.erase(std::remove(sFooter2.begin(), sFooter2.end(), "amp;"), sFooter2.end());
Run Code Online (Sandbox Code Playgroud)

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

c++ string arguments cstring visual-c++

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

标签 统计

arguments ×1

c++ ×1

cstring ×1

string ×1

visual-c++ ×1