关于字符串任意输入并且识别空格的问题
#include<iostream>#include<string>
using namespace std;
class Person
{
private:
string num; //编号
string name; //姓名
public:
Person();
~Person()
{}
void Person::enter();
void print();
};
Person::Person()
{
num='\0';
name='\0';
}
void Person::enter() //Person类数据信息的输入
{
cout<<"输入编号:";
cin>>num;
cout<<"输入姓名:";
cin>>name;
}
void Person::print() //Person类数据信息的输出
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
}
class Teacher:public Person
{
private:
string zhichen; //职称
string bumen; //部门
public:
Teacher():Person()
{
zhichen='\0';
bumen='\0';
}
~Teacher()
{}
void enter()
{
Person::enter();
cout<<"输入职称:";
cin>>zhichen;
cout<<"输入部门:";
cin>>bumen;
}
void print()
{
Person::print();
cout<<"职称:"<<zhichen<<endl;
cout<<"部门:"<<bumen<<endl;
}
};
int main()
{
Teacher t1;
cout<<"教师信息输入:"<<endl;
t1.enter();
cout<<"***************************************"<<endl;
cout<<"教师信息显示:"<<endl;
t1.print();
return 0;
}
Teacher类中的职称和部门如果要输入空格怎么改?如输入职称中:gaoji jiaoshi