[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
jumping beens, well... jumping programs, aaahuuu-aah
From: |
jalkadir |
Subject: |
jumping beens, well... jumping programs, aaahuuu-aah |
Date: |
5 Oct 2005 05:53:25 -0700 |
User-agent: |
G2/0.2 |
By jump I mean ending unexpectedly.
The program below has an unusual behaviour, when the noted lines are
not present the program terminates disregarding the rest of the lines.
I have seen this type of behaviour before, but I can't find to recall
the source, the needy greedy source, of the problem. I, however, was
able to remember that the problem was resolved, temporarily, by using
'std::cin.get()', but I am afraid this will lead to a bug in the
future.
Can anyone help me by explaining what causes this type of behaviour,
why my solution works and, most importantly, how to solve the problem.
Thanks in advance
---
void getData(){
jme::Address address2;
std::string str;
char* cstr;
std::cout.flush();
//std::cin.get().flush();
str.clear();
std::cout << "House/Appartment # ";
std::cin >> str;
std::cin.get(); // Without this line the program jumps <====
address2.setUnitNumber(str);
std::cout << "Enter street name: ";
std::cin.get(cstr,255);
address2.setStreetName(cstr);
str.clear();
std::cout << "City/Town: ";
std::cin >> str;
address2.setCity(str);
str.clear();
std::cout << "Province/State: ";
std::cin >> str;
address2.setProvince(str);
str.clear();
std::cout << "Country: ";
std::cin >> str;
address2.setCountry(str);
str.clear();
std::cout << "Postal Code: ";
std::cin >> str;
address2.setPostalCode(str);
std::cin.get();
Display(address2, "getData()");
}
- jumping beens, well... jumping programs, aaahuuu-aah,
jalkadir <=