我无法编译程序。错误发生在第165-177行。我添加的只是对字母存在的测试,我收到了错误,希望你能帮忙! 完整代码http://pastebin.com/embed.php?i=WHrSasYk
(以下是代码)
do
{
cout << "\nCustomer Details:";
cout << "\n\tCustomer Name:";
cout << "\n\t\tFirst Name:";
getline (cin, Cust_FName, '\n');
if (Quotation::Cust_FName.length() <= 1)
ValidCustDetails = false;
else
{
// Error line 165!
for (unsigned short i = 0; i <= Cust_FName.length; i++)
if (!isalpha(Quotation::Cust_FName.at(i)))
ValidCustDetails = false;
}
cin.ignore();
cout << "\t\tLast Name:";
getline (cin, Cust_LName, '\n');
if (Cust_LName.length () <= 1)
ValidCustDetails = false;
else
{
// Error line 177!
for (unsigned short i = 0; i <= Cust_LName.length; i++)
if (!isalpha(Cust_LName.at(i)))
ValidCustDetails = false;
}
cin.ignore();
}
while(!ValidCustDetails);
答案 0 :(得分:9)
这些问题是您的问题:
for (unsigned short i = 0; i <= Cust_FName.length; i++)
for (unsigned short i = 0; i <= Cust_LName.length; i++)
// ^^
std::string::length
是一个函数,因此您需要使用parens调用它:
for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)
答案 1 :(得分:2)
我怀疑Cust_LName
是std::string
所以你应该在()
之后添加length
:
Cust_LName.length()