【发布时间】:2017-11-29 21:02:21
【问题描述】:
如何将所有\ 更改为\\?
我想创建地址来处理文件:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str = "C:\\user\\asd";
replace(str.begin(), str.end(), '\\', '\\\\');
cout << str;
return 0;
}
我收到一个错误:
F:\c++\tests\regex\main.cpp|8|error: no matching function for call to 'replace(std::basic_string
::iterator, std::basic_string ::iterator , 字符, int)'|
如何在 C++ 中使用 char 数组(没有函数)完成这项工作?
【问题讨论】:
-
'\\\\'是多字节字符,不能用char表示。'\\\\'与"\\"不同。 -
您的问题是关于将 / 更改为 // 但您的代码使用 \ 和 \\.
-
谢谢,怎么办?