简体   繁体   中英

C++ Incomplete type is not allowed

written below is my code for writing usernames and passwords to a file. Everything seems to be ok except for the createUser() function.

#include <iostream>
#include <stdio.h>
#include <string>
#include "login.h"
#include <fstream>

std::string user;
std::string pass;

struct Users {
    std::string username;
    std::string password;
};

void createUser(user, pass) {
    Users new;
    new.username = user;
    new.password = pass;
    ofstream inFile;
    inFile.open("users.txt");
    inFile << User.username << User.password;
    inFile.close()
}

int main(){
    createUser(Users.username, Users.password);
    return 0;
}

The error here is "incomplete type is not allowed" I am assuming it has to do something with the structure i have used but i dont exactly know what. It also says that it expects a ";" after the { bracket at line 15 (void createUser(){)

您必须在createUser函数中声明类型:

void createUser(const std::string& user, const std::string& pass) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM