-3
好吧,所以我得到兩個錯誤。C++註冊和登錄程序幫助需要
- 無效指針加法[在(用戶名+ 「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. 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";
}
}
使用'std :: string'而不是'char []'。 '#include'不是標準的C++。你使用Turbo C++嗎? –
耶兄弟,我上面提到它:P –
請[編輯]你的問題提供[mcve]。 –