设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 877|回复: 2
打印 上一主题 下一主题

[原创]用户输入问题

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-3 00:50:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class User
{
private:
char uid[10],pid[10];
public:
User(char u[],char p[])
{
strcpy(uid,u);
strcpy(pid,p);
}
};
void reg()
{
char u[10],p[10];
cout<<"\n请输用户名:";
cin>>u;
cout<<"\n请输密码: ";
cin>>p;
User myself(u,p);
fstream file;
file.open("text.txt",ios::app);
file.write((char *)&myself,sizeof(myself));
file.close();
cout<<"!!!!!!恭喜您成为本会员!!!!!!\n";
cout<<"-----------------\n\n";
}
void keeg()
{
char a[10],b[10];
cout<<"\n请输用户名:";
cin>>a;
cout<<"\n请输密码: ";
cin>>b;
User myself(a,b);
fstream file;
file.open("text.txt",ios::in);
file.read((char *)&myself,sizeof(myself));
while(!file.eof())
{
file.read((char *)&myself,sizeof(myself));
cout<<"用户名:"<<a<<endl;
cout<<"密码: "<<b<<endl;

}
file.close();
}
void main()
{
int a;
while(1)
{
cout<<"请选择您要执行的程序.\n";
cout<<"---------------------\n";
cout<<"1-创建用户\n";
cout<<"2-登录\n";
cout<<"0-退出\n";
cout<<"请输入0~2的数字";
cin>>a;
switch(a)
{
case(1):
reg();
break;
case(2):
keeg();
break;
case(0):
return;
}
}
}
2#
发表于 2009-11-3 00:50:57 | 只看该作者
#include<iostream.h>
class Sentence
{
private:
char *a;
public:
Sentence(char * b)
{
a=b;
cout<<"类Sentence构造函数 "<<b<<"\n";
}
virtual ~Sentence()
{

cout<<"类Sentencer的析构函数"<<"\n";
}
};
class Phrase :public Sentence
{
public:
Phrase(char *p):Sentence(p)
{
cout<<"类 Phrase构造函数 "<< p<<"\n";
}
~Phrase()
{
cout<<"类Phraser的析构函数"<<"\n";
}
};
void main()
{
Sentence *person2;
person2=new Phrase("bbb");
delete person2;
}
回复 支持 反对

使用道具 举报

3#
发表于 2009-11-3 00:50:58 | 只看该作者
头文件重载


#include<iostream.h>
class student
{
private:
int age;
public:
friend istream & operator >>(istream &i,student &s);
friend ostream & operator <<(ostream &o,student &s);
};
istream & operator >>(istream &i,student &s)
{
i>>s.age;
return i;
}
ostream & operator <<(ostream &o,student &s)
{
o<<s.age;
return o;
}
void main()
{
student s;
cout<<"输入年龄: ";
cin>>s;
cout<<"\n";
cout<<"年龄是: "<<s<<"\n";
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-18 04:48 , Processed in 0.100939 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表