C++ c++;需要注册和登录程序帮助
好的,我有两个错误C++ c++;需要注册和登录程序帮助,c++,logging,C++,Logging,好的,我有两个错误 无效的指针添加[在(用户名+“.txt”行中] 函数getline应该有一个原型 这是密码,我正在登记/注册/登录表格。稍后将为其添加更多功能,例如***密码格式和密码限制。到目前为止,我被困在这里,不知道如何继续。此外,我被迫使用Turbo C++,因为学校: 请为MacOSX推荐一些好的编译器。 谢谢 #包括 #包括 #包括 #包括 #包括 无效寄存器_user(); 无效登录用户(); 无效主菜单(); int IsLoggedIn() { 字符用户名[20]、密码[2
#包括
#包括
#包括
#包括
#包括
无效寄存器_user();
无效登录用户();
无效主菜单();
int IsLoggedIn()
{
字符用户名[20]、密码[20]、un[20]、pw[20];
cout不能对C样式的字符串使用运算符“+”
您需要使用strcat()
或snprintf
另外,使用fscanf
或fread
或fgets
读取字符数组
不能在C样式字符串(字符数组)上使用运算符=
,请使用strcmp
。运算符==
将比较指针中的值,而不是指向的文本
如果要使用C样式字符串,我强烈建议您查看str*()
函数系列。使用std::string
而不是char[]<代码> >包含< <代码> >不是标准C++。你使用Turbo C++吗?是的,Bro,我上面提到过:请你的问题提供一个。如果你要使用<代码> Goto ,通常的做法是把标签放在它自己的,单独的行上(这样就更容易找到)。。您可能希望使用嵌套循环而不是goto
。请在internet上搜索“意大利面代码goto”。
#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. Register\n2. Login\nYour 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";
}
}