Reputation: 61
I'm having trouble getting my program to compile. The error is happening on line 165-177. All I added was the test for the presence of letters and I got an error, hope you can help! Full Code http://pastebin.com/embed.php?i=WHrSasYk
(Attached below is code)
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);
Upvotes: 3
Views: 31625
Reputation: 217275
I suspect that Cust_LName
is a std::string
so you should add ()
after length
:
Cust_LName.length()
Upvotes: 3
Reputation: 169018
These lines are your problem:
for (unsigned short i = 0; i <= Cust_FName.length; i++)
for (unsigned short i = 0; i <= Cust_LName.length; i++)
// ^^
std::string::length
is a function, so you need to invoke it with parens:
for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)
Upvotes: 10