求助,字符指针输入和输出问题
#include <iostream>using namespace std;
class Sudent
{
public:
void set_student();
void show_student();
private:
int number;
char name[20];//这里呢,我问过老师,老师说可以用字符指针来存储字符(就是存字符串的首地址),那么在这程序中呢,name是需要键盘输入的,可是我翻书只找到字符指针的赋值,没有直接输入,请问一下高手,字符指针的输入是整体输入,还是要用循环来输入呢?或者还要用到什么运算符呢?
char subject[15];
int klaso;
char sex[2];
float scores;
};
void Sudent ::set_student()
{
cout<<"请输入学号:"<<endl;
cin>>number;
cout<<"请输入姓名:"<<endl;
cin>> name;
cout<<"请输入专业:"<<endl;
cin>>subject ;
cout<<"请输入班级:"<<endl;
cin>>klaso;
cout<<"请输入性别:"<<endl;
cin>>sex ;
cout<<"请输入成绩:"<<endl; cin>>scores;
}
void Sudent::show_student()
{
cout<<"number:"<<number<<endl;
cout<<"name:"<< name<<endl;
cout<<"subject:"<< subject<<endl;
cout<<"klaso:"<< klaso<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"scores:"<<scores<<endl;
}
int main()
{
Sudent a;
a.set_student();
a.show_student();
return 0;
}