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...