找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 882|回复: 2

[原创]用户输入问题

[复制链接]
发表于 2009-11-3 00:50:56 | 显示全部楼层 |阅读模式 IP:江苏扬州
#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;
}
}
}
发表于 2009-11-3 00:50:57 | 显示全部楼层 IP:江苏扬州
#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;
}
回复

使用道具 举报

发表于 2009-11-3 00:50:58 | 显示全部楼层 IP:江苏扬州
头文件重载


#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";
}
回复

使用道具 举报

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

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 05:23 , Processed in 0.254239 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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