在C ++中从getline获取奇怪的符号(如复选标记)

时间:2018-10-05 00:24:39

标签: c++

我试图制作一个有关黑客行为的C ++控制台游戏,但是当我使用cin时,它并不像我们所知道的那样不计入空格,因此我尝试使用getline(cin,command)(command是我的字符串名称)。但是现在我从何处得到奇怪的复选标记符号和框?

    void PrintDirectory() {
    cout << Directory << "/>> ";
}
bool PlayingMission(int MissionNumber) {
    if (CurrentMission == MissionNumber) {
        return true;
    }
    else {
        return false;
    }
}
string TearWhiteSpace(string cmd) {
    char TempStringChar[cmd.length()];
    int Count = 0;
    for (int i=0; i<cmd.length(); i++) {
        if (cmd[i] != ' ') {
            TempStringChar[Count] = cmd[i];
            Count++;
        }
    }
    return string(TempStringChar);
}
void PlayMission(int MissionNumber) {
    switch(MissionNumber) {
        case 1:
            PrintDirectory();
            cin.ignore();
            getline(cin, Command);
            ReturnCommandInfo(Command);
            CheckForCompletion(CurrentMission);
    }
}
string ReturnCommandInfo(string cmd) {
    string NewCMD = TearWhiteSpace(cmd);
    cout << NewCMD;
    if (NewCMD == "help") {
        for (int i=0; i<NumberOfCommands; i++) {
            cout << Commands[i] << CommandHelp[i] << endl;
        }
    }
    else if (NewCMD[0] == 'c' && NewCMD[1] == 'r' && NewCMD[2] == 'a' && NewCMD[3] == 'c' && NewCMD[4] == 'k') {
        cout << "oof";
        PlayMission(CurrentMission);
    }
    else {
        cout << "Invalid Command, type 'help' to get a list of commands.\n";    
    }
    PlayMission(CurrentMission);
}

0 个答案:

没有答案