我正在尝试使用 Eclipse 通过 C++ 中的以下函数测试字符串输入是否合法:
#include <string>
bool testLegal::checkData(std::string &input, int ®) {
//test to see if pitchnames are legal
std::string toneClasses = "CDEFGAB";
std::string accidentals = "#b";
std::string toTest;
try {
//TEST 1 IS the pitch name legal?
toTest = input.substr(0, 1);
if (_isLegal(toTest, toneClasses) == false)
throw dataClean(2, "The pitch name you entered is illegal. Please correct it!");
//TEST 2 to see if there is a second character in the pitch name and whether it is a sharp or flat
toTest = input.substr(1);
if (input.length() == 2 && _isLegal(toTest, accidentals) == false)
throw dataClean(3, "The second character in the pitch name must be a sharp or flat");
} catch (const cExceptions& e) {
throw dataClean(4, "There is an error in the data you inputed. Please re-enter");
}
return true;
}
但是,我收到关于 .substr 参数的“无效参数”错误。我尝试了各种解决方案但没有成功。奇怪的是,该函数在 Netbeans 和 Codelite 中运行都没有任何问题。我将不胜感激任何想法是如何解决这个问题。期待中的Thx...