我想将staff_id输入为字符串,但我遇到了错误

i want to input staff_id as string but i got error for it

提问人:mils 提问时间:11/15/2023 最后编辑:UpAndAdammils 更新时间:11/15/2023 访问量:13

问:

我该如何解决这个问题,我的staff_id在 int 中并且我想按原样输入?

void registerAccount() {
    staff newacc;

    Menu rgMenu;
    rgMenu.header = "Registration";
    rgMenu.addOption("ID");
    rgMenu.addOption("Username");
    rgMenu.addOption("Password");
    rgMenu.addOption("Email");
    rgMenu.addOption("Staff Name");
    rgMenu.addOption("Staff Position");
    rgMenu.addOption("Staff Contact");
    rgMenu.addOption("Level");
    rgMenu.addOption("Register");
    rgMenu.addOption("Back"); 


    string tmpinput;
    int input;
    bool valid = true;
    while (1) {

        switch (rgMenu.prompt()) {
        case 1:
            cout << "Insert staff id:";
            cin >> input;
            newacc.staff_id = input;
            rgMenu.setValue(0, newacc.staff_id);
            break;
        case 2:
            cout << "Insert Username:";
            cin >> newacc.username;
            rgMenu.setValue(0, newacc.username);
            break;
        case 3:
            cout << "Insert password:";
            cin >> tmpinput;
            if (tmpinput.length() < 6) {
                cout << "Password must be at least 6 character long";
                _getch();
            }
            else {
                newacc.password = tmpinput;
                rgMenu.setValue(1, newacc.password);
            } 
            break;
        case 4:
            cout << "Insert email:";
            cin >> newacc.email;
            rgMenu.setValue(2, newacc.email);
            break;
        case 5:
            cout << "Insert name:";
            cin >> newacc.staff_name;
            rgMenu.setValue(3, newacc.staff_name);
            break;
        case 6:
            cout << "Insert position:";
            cin >> newacc.staff_position;
            rgMenu.setValue(4, newacc.staff_position);
            break;
        case 7:
            cout << "Insert contact:";
            cin >> newacc.staff_telno;
            rgMenu.setValue(5, newacc.staff_telno);
            break;
        case 8:
            cout << "Insert level:";
            cin >> newacc.level;
            rgMenu.setValue(6, newacc.level);
            break;
        case 9:
            valid = true;
            if (valid) { 
                newacc.insert();
                cout << "Registered";
                _getch();
                return;
            }
            else {
                cout << "Please re-check your informations";
                _getch();
            }
            break;
        case 10:
            return;
        default:
            break;
        }
    }

}

我已经将输入初始化为 but 在这里“ rgMenu.setValue(0, newacc.staff_id);我遇到了无法声明newacc.staff_id将其输入系统的问题,并且出现错误 严重性代码说明 项目文件行抑制状态 错误(活动)E0415 不存在合适的构造函数来将“int”转换为“std::basic_string<char, std::char_traits, std::allocator>” 演示帮助类 C:\Users\User\Downloads\Workshop1_CPP-main\Workshop1_CPP-main\DEMO 帮助类\DEMO 帮助类\main.cpp 89int

字符串 visual-c++ 整数

评论


答: 暂无答案