I am creating a class for a project using an Emericc axe. The goal of this class is to use the error frames to return a message. I have to use only STL's std::string variables. However, the IDE doesn't recognize any string manipulation after one of the find functions.
Note that I'm French, so the variables I use are in my language (the code is pretty simple tho).
The error I encounter is in this function:
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 tells me : [C++ Error] ErrMericc.cpp(1): impossible to call code execution, because of source code errors. When I double click on this error message, it brings me at the first line of source code in the file.
The error message doesn't seem to stop popping except if I comment out the "trame.find(',', posVirg);".
Could you please explain me where my error is?
EDIT:
It looks like C++ Builder 6 just doesn't like the code line...
This works:
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()
This doesn't:
//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()
Weird.
I'm starting to think the problem comes from the IDE. So far, I've tried copying and moving the files into a new folder, but the malfunction isn't affected.
Turns out the error came from my using of the push_back() function : I can push back only one char at a time.
Inputing multiple values in one memory location, made to contain one char, wasn't a good idea.
Apparently, C++Builder 6 just didn't know what to do as the errors came from my use of something in the stl.
So I shouldn't have done :
trame.push_back("Erreur 200 : "+errors[200]+". La trame envoyée n'est pas une trame d'erreur.");
But :
trame = string("Erreur 200 : ") + errors[200] + string(". La trame envoyée n'est pas une trame d'erreur.");