hi,
for some reason the line "cout << "Enter your name : "; getline(cin, name);" is acting up. can someone please check it out for me? i'm using it with vectors and a class.
file.cpp
file.hCode:#include <iostream> #include <string> #include <vector> #include "file.h" using namespace std; int my_class::askUser() { cout << "Enter your name : "; getline(cin, name); cout << "building number : "; cin >> build_num; cout << "apartment number: "; cin >> apt_num; // cout << "Enter your name : "; getline(cin, name); //placing it here gives me the same problem return 0; } void my_class::dispInfo() const { cout << "customer name is " << name << endl; cout << "building number is " << build_num << endl; cout << "apartment number is " << apt_num << endl; } int main() { vector<my_class> one(6); int i; for(i=0; i<one.size(); i++) { one[i].askUser(); one[i].dispInfo(); } return 0; }
on run, after the first execution of the loop, it should ask for the the string input again but it skips it. i have no idea how to correct it. the logic is perfect i think.Code:#include <iostream> #include <string> using namespace std; class my_class { public: int askUser(); void dispInfo() const; private: int build_num; int apt_num; string name; };
thanks,
barneygumble742