| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 713 人关注过本帖
标题:我自己写的 登录与注册 的框架 分享一下!!!
只看楼主 加入收藏
xxlovemf
Rank: 2
等 级:论坛游民
威 望:1
帖 子:49
专家分:88
注 册:2009-8-6
结帖率:80%
收藏
 问题点数:0 回复次数:1 
我自己写的 登录与注册 的框架 分享一下!!!
程序代码:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;//注册账号(用户名与密码)

int main(int argv,char **argc)
{
    string name,passwd,total;
    ofstream os("d:\data.dat",ios::app);//创建文件 以追加的方式
    string::size_type pos;//子串的位置

    if(!os)
    {
        cerr<<"ofstream error!"<<endl;
        exit(1);
    }

    cout<<"------Register Name------"<<endl;
    cout<<"please input your name:"<<endl;
    cin>>name;
    ifstream is("d:\data.dat");//读取文件
    is >> total;//表示文件中的所有字符串
    pos=total.find(name);//用户名在文件中的位置
       
    if(pos != -1)//若用户名存在
    {
        cout<<"this name is exist!"<<endl;
    }
    else//若用户名不存在
    {
        cout<<"please input your passwd:"<<endl;
        cin>>passwd;
        os<<name<<":"<<passwd<<",";//保存用户名与字符串
        cout<<"------register success------!"<<endl;
    }

    is.close();
    os.close();

    return 0;
}
写得比较简陋,有望大家指出意见!!!!

[ 本帖最后由 xxlovemf 于 2010-10-1 15:30 编辑 ]
搜索更多相关主题的帖子: 登录 分享 注册 框架 
2010-10-01 15:27
xxlovemf
Rank: 2
等 级:论坛游民
威 望:1
帖 子:49
专家分:88
注 册:2009-8-6
收藏
得分:0 
程序代码:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;//登录账号(用户名与密码)

int main(int argv,char **argc)
{
    string name,passwd,total,test;
    ifstream is("d:\data.dat");//读取文件
    string::size_type pos;//子串的位置

    if(!is)
    {
        cerr<<"ifstream操作错误!"<<endl;
        exit(1);
    }

    cout<<"------Login Name------"<<endl;
    is>>total;
    cout<<"please input your name:"<<endl;
    cin>>name;
    cout<<"please input your passwd:"<<endl;
    cin>>passwd;
    test=name+":"+passwd;//用户名+密码
    pos=total.find(test);//用户名+密码在文件中的位置

    if(pos!=-1)//若用户名存在
    {
        Sleep(3e3);//延时3秒
        cout<<"------login sucsess------!"<<endl;
    }
    else//若用户名不存在
    {
        cout<<"name or passwd is error!"<<endl;
    }

    is.close();

    return 0;
}
2010-10-01 15:29
快速回复:我自己写的 登录与注册 的框架 分享一下!!!
数据加载中...
 
   



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

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