直接上代码,
#include#include #include #include #include using namespace std; void denglu() { while(1) { system("cls"); int sr; cout << "登录"< > zh; cout << "密码:"; cin >> mm; ifstream ifs; ifs.open("yhzl.txt", ios::in); while (ifs >> u1 && ifs >> u2) { if (u1 == zh && u2 == mm) { cout << u1 << " 你好" << endl; cout< > x; if(x==u2) { ofstream oof; oof.open("temp.txt", ios::binary | ios::out); //temp.txt用于交换 cout << "新密码:"; cin >> y; oof << u1 << "t" << y << endl; oof.close(); ofstream ofs; ifstream iof; ofs.open("yhzl.txt", ios::binary | ios::out); iof.open("temp.txt", ios::binary | ios::out | ios::in); while (iof >> u1 >> y ) { ofs << u1 << "t" << y << endl; } cout << "修改成功,请重新登录"< > u1 && ifs >> u2 ) { if (u1 == zh ) { continue; } oof << u1 << "t" << u2 < > u1 >> u2 ) { ofs << u1 << "t" << u2 << endl; } ofs.close(); iof.close(); } if(sr=='2') { continue; } } if(sr=='3') { system("cls"); cout<<"已退出登录"< > zh; ifstream ifs; ifs.open("zh.txt", ios::in); while (ifs >> zhe ) { if (zh == zhe) { cout << "已有账号,是否登录?" << endl; cout< >mm; ofstream ofs; ofs.open("yhzl.txt", ios::out|ios::app); //若是电脑读取不了中文的,只能用首字母或数字代替。 ofs << zh << "t" << mm << endl; //这里的“t”表示空格,电脑会自动为我们把数据对齐 ofs.close(); ofs.open("zh.txt", ios::out|ios::app); //应该是我技术问题,若是会单项查找,可以自己尝试 ofs << zh << endl; ofs.close(); cout << "注册成功" < 这系统的是用txt文件存储的,
先了解一下文件流,
像
ofs.open("yhzl.txt", ios::binary | ios::out);
ofs.open是打开,并以某种方式打开,
某种方式取决与ios::后面的代码,向上面的binary,out,还有in, app,ate等
ios是关联 ifstream的,
可以这样引用ifstream
#include
#include
就是ofs的头文件,而 是常见输出输入的头文件,如cout,cin ios::后面的代码意思就像下面这表格
代码 用途 in 读取txt out 写入txt app 输入标全部跳到最后面 ate 打开输入标跳到最后面 binary 用二进制打开 trunc 把之前写的扔掉
ofs.open("yhzl.txt", ios::binary | ios::out);
这个就是,啊
先不说,
你猜
答案在这 答案
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
你猜
答案
以二进制写的方式打开yhzl.txt
我爱bug,快说说bug吧



