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 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型