我正在使用 Emericc 斧头为项目创建一个类。此类的目标是使用错误帧返回消息。我必须只使用 STL 的 std::string 变量。但是,IDE 无法识别任何一个查找函数之后的字符串操作。
请注意,我是法国人,所以我使用的变量是我的语言(代码非常简单)。
我遇到的错误是在这个函数中:
string ErrMericc::ErrTrame(string trame)
{
/*
trame(fr) = frame(eng)
virgule(fr) = comma(eng) [I shortened "virgule" to "virg" in a variable]
*/
this->trame=trame;
trame.find('!', posExcl); //this marks the beginnig of the error number
if(posExcl == string::npos)
{
trame.clear(); //clearing in case the variable is not empty
//in case this is not an error frame
trame.push_back("Erreur 200 : "+errors[200]+". La trame envoyée n'est pas une trame d'erreur.");
return trame;
}
else
{
trame.find(',', posVirg); //here is the error
//starting here, no function using a string is recognized by the IDE
//and I don't find why
nb.push_back(trame.substr(posExcl+2, posVirg)); //unrecognized push_back() and substr()
errNb=StrToInt(trame.c_str());
trame=errors[errNb];
return "Erreur "+IntToStr(errNb)+" : "+trame;
}
}
C++Builder 6 告诉我:[C++ 错误] ErrMericc.cpp(1): 由于源代码错误,无法调用代码执行。当我双击此错误消息时,它会将我带到文件中源代码的第一行。
除非我注释掉“trame.find(',', posVirg);”,否则错误消息似乎不会停止弹出。
你能解释一下我的错误在哪里吗?
编辑:
看起来 C++ Builder 6 只是不喜欢代码行......
这有效:
trame.find(',', posVirg); //here is the error
//starting here, no function using a string is recognized by the IDE
//and I don't find why
nb.push_back(trame.substr(posExcl+2, posVirg)); //unrecognized push_back() and substr()
这不会:
//here is the error
//starting here, no function using a string is recognized by the IDE
//and I don't find why
trame.find(',', posVirg);
nb.push_back(trame.substr(posExcl+2, posVirg)); //unrecognized push_back() and substr()
诡异的。
我开始认为问题来自IDE。到目前为止,我已经尝试将文件复制并移动到新文件夹中,但故障不受影响。