注册 登录
编程论坛 C++教室

输入的问题

kame 发布于 2007-08-10 15:39, 547 次点击
#include<fstream.h>
class CStudent
{
char n[20],sex;
int num,age,maths,computer,english;
public:
/* CStudent(int no,char *name,char s,int c,int m,int e)
{
num=no;n=name;sex=s;computer=c;mahts=m;english=e;
}*/
void input(CStudent S1)
{
bool a=true;char b;

while(a==true)
{
static int i=1;
cout<<"输入学生信息"<<endl;num=i;
cout<<"姓名"<<endl;cin>>S1.n;
cout<<"性别"<<endl;cin>>S1.sex;
cout<<"计算机"<<endl;cin>>S1.computer;
cout<<"数学"<<endl;cin>>S1.maths;
cout<<"英语"<<endl;cin>>S1.english;
cout<<"是否要继续输入学生信息Y(y)/N(n)"<<endl;
cin>>b;
if(b=='y' || b=='Y')
a=true;
else
a=false;
ofstream out("string2.txt",ios::app);
out.write((char *)&S1,sizeof(S1));
out.close();
i++;

}
}
};
void main()
{
CStudent S1;
S1.input(S1);
}
在输入的时候跳到输入"计算机"的时候就过去了,貌似是因为输入字符和INT之见要加什么分隔符?
忘记了 用COUT.PUT()貌似无用
望指教;

[此贴子已经被作者于2007-8-10 15:39:25编辑过]

5 回复
#2
野比2007-08-10 18:54
输完一个就回车..
#3
zhss52007-08-10 20:52

sex为char类型,只占一个字节。
但输入一个中文占两个字节。

#4
kame2007-08-11 13:31
谢谢zhss5
问题解决了 在输入SEX的时候一直打MAN 怪不得一下子就跳到结束了
哈哈 好低级的问题 以后会注意
#5
wxt3352007-08-11 23:23

#include "iostream"
using namespace std ;


#include<fstream.h>

有什么区别

#6
圆圆的鸟蛋2007-08-11 23:48
以下是引用wxt335在2007-8-11 23:23:51的发言:

#include "iostream"
using namespace std ;


#include<fstream.h>

有什么区别


应该是#include <iostream>
using namespace std ;

fstream是指文件的输入输出流。

1