runtime error

When I run this for some reason i get: terminate call after throwing an instance of 'std:: length_error' what(): basic_string::resize
This application ahs requested the runtime to terminate in an unusual way. please contact the applications support team for more information...

1
2
3
4
5
6
7
	//x.resize(x.length-1)// str.resize (14);
	for(int i = 0; i < length; i++){
		string city = hr[i].address.city;
		int length = hr[i].address.city.length()-1;
		city.resize(length);
		hr[i].address.city = city;
	}	
You're doing all that just to remove the last character from address.city? Why not resize ht[i].address.city directly?

Your problem is you aren't checking if the string is empty before resizing it.
Topic archived. No new replies allowed.