#ifndef __SPLIT_H_
#define __SPLIT_H_
#endif
//__SPLIT_H_
void StringSplit(string s,char splitchar,vector<string>& vec)
{
if(vec.size()>0)//保证vec是空的
vec.clear();
int length = s.length();
int start=0;
for(int i=0;i<length;i++)
{
if(s == splitchar && i ==
0)//第一个就遇到分割符
{
start +=
1;
}
else
if(s == splitchar)
{
vec.push_back(s.substr(start,i - start));
start = i+1;
}
else
if(i == length-1)//到达尾部
{
vec.push_back(s.substr(start,i+1
- start));
}
}
}
报错内容
In file included from a.cpp:24:
split.h:23: error: variable or field `StringSplit' declared void
split.h:23: error: `string' was not declared in this scope
split.h:23: error: expected primary-expression before "char"
split.h:23: error: `vector' was not declared in this scope
split.h:23: error: `string' was not declared in this scope
split.h:23: error: `vec' was not declared in this scope
split.h:24: error: initializer expression list treated as compound expression
split.h:24: error: expected `,' or `;' before '{' token |