在子函数中对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]