请教关于字符串的输入问题
程序代码:
#include<iostream> #include<string> using namespace std; class stu { public: void set(); void put(); private: int num; string name; string phone; }; void stu::set() { cout << "num is:"; cin >> num; cout << "name is:"; cin>>name; cout << "phone is:"; cin >> phone; cout<<endl; } void stu::put() { cout << "num\t" << "name\t" << "phone" << endl; cout << num << "\t" << name << "\t" << phone << endl; } int main() { class stu student1; student1.set(); student1.put(); return 0; }
输入 1 li ming 124345时,来不及输入12345就直接得到结果了,书上好像看到过,但找不到了,请问该如何修改