我正在从这里得到一些信息:如何在C++字符串中找到第一个字符
当我尝试将其实现到我的代码中时,我得到错误not1未在此范围内声明.
void ASTree::indent(int ind, int inc) {
std::string theText;
for (std::vector<ASTree*>::const_iterator i = child.begin(); i != child.end(); ++i) {
switch ((*i)->nodeType) {
case category:
(*i)->indent(ind + inc, inc);
break;
case token:
{
//out << std::setw(indent) << " ";
theText = (*i)->text; // << std::endl;
std::string::iterator firstChar = std::find_if(theText.begin(), theText.end(), std::not1(std::isspace));
theText.erase(theText.begin(), firstChar);
(*i)->text = theText;
}
break;
case whitespace:
//out << (*i)->text;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我对C++有些新意,并在课堂上处理这些项目.
你有这个标题:
#include <functional>
Run Code Online (Sandbox Code Playgroud)
此外,std::not1不仅仅是使用not1它在std命名空间中定义.
我希望你没有写入using namespace std你的代码,无论如何这都是一个坏主意.
好的,在您阅读本评论之后:
get yet another error. :) no matching function for call to ânot1(<unresolved overloaded function type>)â I also updated the code above to show you my current
Run Code Online (Sandbox Code Playgroud)
我想isspace在std命名空间中存在另一个名称的函数,这在解析名称时会导致问题.
所以这里有两个解决方案.一个接一个地尝试:
::isspace.不使用std.只是::isspace.看它是否有效!或者,显式转换以帮助编译器选择所需的重载,如
std::not1(((int)(*)(int))(std::isspace));
Run Code Online (Sandbox Code Playgroud)由于演员看起来非常笨拙,你也可以使用typedef,如:
//define this inside the function, or outside the function!
typedef int (*fun)(int);
//then do this:
std::not1((fun)(std::isspace))
Run Code Online (Sandbox Code Playgroud)
我希望这对你有帮助.
之前已经看到过类似的问题,请看:
| 归档时间: |
|
| 查看次数: |
1759 次 |
| 最近记录: |