我在书“Accelerated C++”(第6.1.1章)中找到了下面的代码,但我无法编译它。问题在于find_if
行。我有必要的包括(矢量,字符串,算法,cctype)。任何想法?使用find_if分割字符串
感谢,贾巴
bool space(char c) {
return isspace(c);
}
bool not_space(char c) {
return !isspace(c);
}
vector<string> split_v3(const string& str)
{
typedef string::const_iterator iter;
vector<string> ret;
iter i, j;
i = str.begin();
while (i != str.end())
{
// ignore leading blanks
i = find_if(i, str.end(), not_space);
// find end of next word
j = find_if(i, str.end(), space);
// copy the characters in [i, j)
if (i != str.end()) {
ret.push_back(string(i, j));
}
i = j;
}
return ret;
}
如何对这些编译错误? :) – GManNickG 2009-12-16 23:35:02
确实。在包含和'使用命名空间标准;'扔在这里完美地编译;请告诉我们你有什么不同。 – ephemient 2009-12-16 23:42:47
这个例子在这里编译。你应该给出一个完整的最小例子。 – anno 2009-12-16 23:46:38