weixin_43674099 2018-11-12 05:46 采纳率: 0%
浏览 540

C++对Spring类进行replace操作报错问题

在子函数中对Spring类进行操作,结果报错,代码和错误原因如下。。。
请各位大佬给小白一些帮助。。。

#include
#include
#include
#include
#include

using namespace std;

int analyse_line(const string& str)
{
string P=",";
string s;
int count = 0;
int begin=-1;
int t = 0;
while((begin=str.find(P,begin+1))!=string::npos)
{
char i = str[begin+1];
char j = str[begin-1];
char k = '\"';
count++;
if ( i == k | j == k){}
else
{
str.replace(begin,1,"/");//出错位置
}
begin=begin+P.length();
}

}
vector split(const string& str, const string& delim)
{
vector res;
if ("" == str) return res;
//先将要切割的字符串从string类型转换为char*类型

char * strs = new char[str.length() + 1]; //不要忘了

strcpy(strs, str.c_str());

char * d = new char[delim.length() + 1];
strcpy(d, delim.c_str());

char *p = strtok(strs, d);
while (p) 
{
    string s = p; //分割得到的字符串转换为string类型  
    res.push_back(s); //存入结果数组  
    p = strtok(NULL, d);
}
return res;

}

int main()
{
ifstream fin("d.csv"); //打开文件流操作
string line;
while (getline(fin, line)) //整行读取,换行符“\n”区分,遇到文件尾标志eof终止读取
{
analyse_line(line);
//string &replace(int p0, int n0,int n, char c);
std::vector res = split(line, ",");
}
return 0;
}

错误原因:28 26 [Error] passing 'const string {aka const std::basic_string}' as 'this' argument of 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::replace(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long long unsigned int]' discards qualifiers [-fpermissive]

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2018-11-12 15:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示