新微赢技术网

标题: [原创]用户输入问题 [打印本页]

作者: 玩QQ名字千万    时间: 2009-11-3 00:50
标题: [原创]用户输入问题
#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
#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
头文件重载


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




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2