| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 423 人关注过本帖
标题:[原创]用户输入问题
只看楼主 加入收藏
271391233
Rank: 1
等 级:新手上路
帖 子:174
专家分:0
注 册:2005-2-24
收藏
 问题点数:0 回复次数:2 
[原创]用户输入问题
#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;
}
}
}
搜索更多相关主题的帖子: 用户 输入 
2006-04-12 13:53
271391233
Rank: 1
等 级:新手上路
帖 子:174
专家分:0
注 册:2005-2-24
收藏
得分:0 

#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;
}


坚持就是胜利>>静心,静思
2006-04-12 13:54
271391233
Rank: 1
等 级:新手上路
帖 子:174
专家分:0
注 册:2005-2-24
收藏
得分:0 

头文件重载


#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";

}


坚持就是胜利>>静心,静思
2006-04-12 13:55
快速回复:[原创]用户输入问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060374 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved