C 注册并登录程序帮助
c++ registration and sign in program help needed
好吧,所以我遇到了两个错误。
- 无效的指针添加[在(用户名 "。txt"行)]
- 函数getline应该具有原型。
这是代码,我正在以形式进行注册/注册/登录。以后将添加更多功能,例如****格式密码和密码的限制。截至目前,我被困在这里,不知道该如何进行。此外,我被迫使用Turbo C 是因为学校)))。请为MacOSX建议一些好的编译器。谢谢!
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void register_user();
void login_user();
void main_menu();
int IsLoggedIn()
{
char username[20],password[20],un[20],pw[20];
cout<<"Enter Username: ";gets(username);
cout<<"Enter Password: ";gets(password);
ifstream read(username + ".txt");
getline(un,read);
getline(pw,read);
if(un==username && pw==password)
{
return 1;
}
else
{
return 0;
}
}
void main()
{
main_menu();
}
void main_menu()
{
int choice;
cout<<"1. Registern2. LoginnYour Choice: "; cin>>choice;
switch(choice)
{
case 1: register_user(); break;
case 2: login_user(); break;
default: break;
}
}
void register_user()
{
char username[20], password1[20],password2[20];
cout<<"Enter Username: ";gets(username);
rev1:cout<<"Enter Password: ";gets(password1);
cout<<"Enter Password again: ";gets(password2);
while (password1!=password2)
{
goto rev1;
}
ofstream file;
file.open(username + ".txt");
file<<username<<endl<<password1;
file.close();
}
void login_user()
{
int chk=IsLoggedIn();
if(chk==1)
{
cout<<"Log in successfull!n";
}
else
{
cout<<"Log in unsucessfull!n";
}
}
您不能将操作员' '用于C风格字符串。
您将需要使用strcat()
或snprintf
。
另外,使用fscanf
或fread
或fgets
读取字符数组。
您不能在C风格字符串(字符数组)上使用操作员==
,使用strcmp
。operator ==
将比较指针中的值,而不是指向的文本。
如果您要使用C风格的字符串,我强烈建议您查看str*()
功能家族。
相关文章:
- C++调用具有 *this 属性的单个帮助程序函数
- 用于检查值是否为其任何参数的帮助程序函数
- 类型限定宏帮助程序
- CoreCLR 中的检测探查器 - 将帮助程序程序集加载到 dotnet 进程的方法
- 编写一个程序,帮助Tudio将MIDI音符转换为名称和八度音阶
- cout 在我的程序上无法正常工作,有人可以帮助我吗?
- 无法将 2D 数组传递到 c++ 中的帮助程序函数中
- C2783: 无法推断帮助程序函数的模板参数
- 需要循环帮助以迭代方式添加到程序集中的总和变量
- 友元函数需要一个帮助程序函数
- 在何处放置与类方法相关的帮助程序函数C++
- 给定概念,SFINAE 帮助程序是否仍在规范中作为未弃用?
- 需要帮助编写一个小程序来将循环乘以 n 个元素和 k 个多重性
- C 注册并登录程序帮助
- 自动售货机程序(帮助)
- 商数程序帮助我
- 第一个C++程序帮助(计算器)
- 简单的程序帮助-发送动态内存指针到函数
- 井字游戏程序帮助
- c++程序帮助:结构体,数组,循环,输入文件,循环不工作