【问题标题】:I have one unspecified error in my basic c++ program我的基本 C++ 程序中有一个未指明的错误
【发布时间】:2017-04-19 07:35:25
【问题描述】:

我的程序中有一个未指明的错误。该程序对用户播放石头剪刀布。我没有更改源代码中的任何内容。但是当我运行程序时,它出现了一个未指定的错误。

代码:

#include <stdio.h>

#include <string>
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include "math.h"
#include <time.h>
#include <cstdlib>

void begin_game();

using namespace std;

int main(){
    SetConsoleTitle("Rock Paper Scissors");

    string enter_to_continue;


    cout<<"Welcome to rock paper scissors \n";
    cout<<"Type begin to start \n";
    cin>>enter_to_continue;

    if (enter_to_continue == "begin"){
        begin_game();
    }

    return 0;
}



//begin game function
    void begin_game(){

    cout<<"\n";

    string player_input;

    bool restarting_game = true;
    //restarting game while loop
    while(restarting_game = (true)){

        restarting_game = false;

        int seed_random = seed_random + 3;
        srand(seed_random);
        int ai_random = rand() % 3+1;

        cout<<seed_random<<endl;
        cout<<"r = rock \n";
        cout<<"p = paper \n";
        cout<<"s = scissors \n \n";

        cout<<"Type r, p, or s \n";
        cout<<"You can type exit to exit game \n \n";
        cin>>player_input;

        if(player_input == "exit"){
        restarting_game = false;
        cout<<"\n";
        exit(0);
        }
        else{
        //rock vs ai
        if(player_input == "r" && ai_random == 1){
        cout<<"The computer chose rock \n";
        cout<<"ITS A TIE RESTARTING \n \n \n";
        cout<<"\n \n \n";
        bool restarting_game = true;
        }
        else if(player_input == "r" && ai_random == 2){
        cout<<"The computer chose paper \n";
        cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n";
        cout<<"\n \n \n";
        restarting_game = true;
        }
        else if(player_input == "r" && ai_random == 3){
        cout<<"The computer chose rock \n";
        cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
        cout<<"\n \n \n";
        restarting_game = true;
        }

        //paper vs ai
        if (player_input == "p" && ai_random == 1){
        cout<<"The computer chose rock \n";
        cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
        cout<<"\n \n \n";
        restarting_game = true;
        }
        else if (player_input == "P" && ai_random == 2){
        cout<<"The computer chose paper \n";
        cout<<"ITS A TIE RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
        cout<<"\n \n \n";
        restarting_game = true;
        }
        else if (player_input == "p" && ai_random == 3){
        cout<<"The computer chose rock \n";
        cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
        cout<<"\n \n \n";
        restarting_game = true;
        }

        //scissor vs ai
        if (player_input == "s" && ai_random == 1){
            cout<<"The computer chose rock \n";
            cout<<"YOU LOST RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
            cout<<"\n \n \n";
            restarting_game = true;
        }
        else if(player_input == "s" && ai_random == 2){
            cout<<"The computer chose paper \n";
            cout<<"YOU WON RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
            cout<<"\n \n \n";
            restarting_game = true;
        }
        else if(player_input == "s" && ai_random == 3){
            cout<<"The computer chose rock \n";
            cout<<"ITS A TIE RESTARTING \n \n \n \n \n \n \n \n \n \n \n \n \n ";
            cout<<"\n \n \n";
            restarting_game = true;
        }
        }
    }
    }

控制台:

C:\Windows\system32\cmd.exe /C ""C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f  Makefile"
"----------Building project:[ aiprogramproject - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/lisa/Desktop/codelight c++/aiprogram/aiprogramproject'
"C:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe" -o ./Debug/aiprogramproject @"aiprogramproject.txt" -L.
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../../mingw32/bin/ld.exe: cannot open output file ./Debug/aiprogramproject.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/aiprogramproject] Error 1
aiprogramproject.mk:78: recipe for target 'Debug/aiprogramproject' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/lisa/Desktop/codelight c++/aiprogram/aiprogramproject'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====

【问题讨论】:

  • “无法打开输出文件./Debug/aiprogramproject.exe:权限被拒绝”看起来像是一个非常明确的错误。检查程序没有运行。
  • 您的 while 循环执行分配 restarting_game = (true),然后“返回”true。也就是说,它不检查restarting_game 是真还是假,它永远循环。

标签: c++ compiler-errors codelite


【解决方案1】:

确保您的程序没有运行。 make clean 然后再试一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2010-11-20
    • 2020-07-06
    • 2016-03-31
    • 2021-07-31
    • 2014-09-07
    相关资源
    最近更新 更多