1

i can't figure out how to solve this error, i've searched online, but any solutions i've found use terms that are beyond me (as i am still a beginner at C++)..so it's been a little tricky to crack this. basically all i'm trying to do here is find the length of newPin, and check to make sure this length is equal to 4. if there's any other way to accomplish this, that'd be great. but otherwise, if there is an easy solution here, i'd love to see it. so here's a snippet of my code and the lovely error that accompanies it.

string GetNewPin(string) {
do {
cout << "Enter new PIN number: ";
cin >> newPin;
} while(int(newPin.length) != 4);
return newPin;
}

h:\pa4\part2.cpp(98): error C2228: left of '.length' must have class/struct/union type

2
Contributors
4
Replies
5
Views
13 Years
Discussion Span
Last Post by GoldenGreg007
1
while(int(newPin.length) != 4);

should be

while( newPin.length() != 4); // length() is a memberfunction of string

K.

0

ahh.. it didn't work now that i tested it; i still get the same error, along with 16 new ones. :sad: oh well, thanks anyway.

0

sorry about all the posts.. i messed around a little more, and changed a few things elsewhere in the program, and tried your line again, which took the error off, thus your solution was correct. i probably still won't finish this project, but at least now i can get it in without errors! thanks again, Zuk.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.