Is there a way to only read in a certain amount (2 in this case) of numbers into an int?
For example, my input looks like:
So, i want to read only two numbers into an int variable. Currently, my program reads all numbers until it hits a non-int character. So, when it gets to the address entry:Code:04Will05Smith0825 Place05Tulsa02OK0538135 05Corey05Black10Elm Street06Dallas02TX0589148
It will read 0825 into the variable, instead of 08.Code:0825 Place
Here is my code:
My output is fine until it hits the address.Code:istream & operator >> (istream & stream, Person & p) { int length = 0; stream >> length; length++; stream.get(p.firstName, length); stream.ignore(); stream >> length; length++; stream.get(p.lastName, length); stream.ignore(); stream >> length; length++; stream.get(p.address, length); stream.ignore(); stream >> length; length++; stream.get(p.city, length); stream.ignore(); stream >> length; length++; stream.get(p.state, length); stream.ignore(); stream >> length; length++; stream.get(p.zipCode, length); stream.ignore(); return stream; }
I've tried declaring a char and typecasting and using atoi, but i still can't get it to work.
Thanks.



LinkBack URL
About LinkBacks


