error: “initializer expression list treated as compound expression”

空扰寡人 提交于 2020-12-30 09:35:08

问题


I'm having an issue compiling the beginnings of a basic password protected file program, I'm getting the above error on line 11, (int login(username,password)). Not sure what's going on here, so it'd be nice if someone could shed some light on the situation.

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

using namespace std;

int i,passcount,asterisks;
char replace, value, newchar;
string username,password,storedUsername,storedPassword;

int login(username,password);
{
    if (username==storedUsername)
    {
        if (password==storedPassword)
        cout<<"Win!";
        else
        cout<<"Username correct, password incorrect."
    }
    else cout<<"Lose. Wrong username and password.";
}

int main()
{
    cout<<"Username: ";
    cin>>username;
    cout<<"Password: ";
    do
    {
    newchar = getch();
    if (newchar==13)break;
    for (passcount>0;asterisks==passcount;asterisks++)cout<<"*";
    password = password + newchar;
    passcount++;
    } while (passcount!=10);
    ifstream grabpass("passwords.txt")
    grabpass>>storedpass;
    grabpass.close();
    login(username,password);

    return 0;
}

回答1:


int login(username,password);
{

should be

int login(string username,string password)
{



回答2:


You may wan't to fix function declaration

int login(username,password);

Should be changed to

int login(const string& username,const string& password);

Also as a style note, you may not want to declare global variable, you can limit scope of most of your variables to local scope in main.




回答3:


You have to specify the data types of username and password.




回答4:


When declaring a user-defined function with parameters, you must declare the parameter types as well.

For example:

int foo(int parameter)
{
    return parameter + 1;
}


来源:https://stackoverflow.com/questions/4281904/error-initializer-expression-list-treated-as-compound-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!