即时通讯试图创建一个登录程序,但发生了错误 [英] im trying to create a login program but an error ocuured

查看:90
本文介绍了即时通讯试图创建一个登录程序,但发生了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <fstream>
#include<string>
#include<conio.h>

using namespace std;

int main() {
    string username, password;
    bool    char filename[] = "myfile.txt";

    ofstream Login(filename, ios::app);

    cout<<"Enter username: ";
    getline(cin, username);

/*---the error start here(could not convert `username' to `bool' ) */
      while(username entered by user == username found in file)
{
          cout<<"Username already exist!! Enter username: ";
          getline(cin, username);
      }


    Login<<username<< " ";
    cout<<"Enter password: ";
    getline(cin, password);
    Login<<password<<"\n";

    Login.close();
    return 0;
    getch();
}

推荐答案

我认为这行
bool char filename[] = "myfile.txt";


只能是

char filename[] = "myfile.txt";


尝试以下代码:

Try this code:

#include <iostream>
#include <fstream>
#include<string>
#include<conio.h>
 
using namespace std;
 
int main() {
string username, password, usernameFromFile;
char filename[] = "myfile.txt";
 
ofstream Login(filename, ios::app);
ifstream ViewLogin(filename);
 
cout<<"Enter username: ";
getline(cin, username);
getline(ViewLogin, usernameFromFile);
 
while(username == usernameFromFile)
{
cout<<"\nUsername already exist!! Enter username: ";
cin>>username;
}
 
 
Login<<username;
cout<<"Enter password: ";
getline(cin, password);
Login<<password<<"\n";
 
Login.close();
return 0;
getch();
}




干杯,
jmrosendal




Cheers,
jmrosendal


这篇关于即时通讯试图创建一个登录程序,但发生了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆