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:
Code:
04Will05Smith0825 Place05Tulsa02OK0538135
05Corey05Black10Elm Street06Dallas02TX0589148
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:
0825 Place
It will read 0825 into the variable, instead of 08.
Here is my code:
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;
}
My output is fine until it hits the address.
I've tried declaring a char and typecasting and using atoi, but i still can't get it to work.

Thanks.