簡體   English   中英

g++:錯誤:<descriptive name> : 沒有這樣的文件或目錄</descriptive>

[英]g++: error: <descriptive name>: No such file or directory

當我使用 while 循環時,vscode 將無法運行我的代碼... 平台:Windows 10 編譯器:Visual Studio 代碼和 Powershell 核心語言:C++

不使用while循環,然后它可以工作,但我需要while循環來再次運行我的程序。

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){

    int replay = 0;
    int input;

    while(input == replay)
    {
        //Creating variables to store
        string celebrity = "Keeves Reeves";
        string guess;

        //Prompt the user
        cout << "Guess this celebrity: He acted as John Wick" << endl;
        getline(cin, guess);


        //Check the answer by using switch statement

        if(guess == celebrity){
            cout << "Congratulations! You are right" << endl;
            input = 3;
        } else if(guess != celebrity)
            cout << "Whoops, that not the right answer..." << endl;
            cout << "If you want to try again, enter '0' to replay, enter '1' to view the answer: ";
            cin >> input;
            if(input = 1){
                cout << "The celebrity was " << celebrity << " ." << endl;
            }
    }

    //Break from while loop
    cout << "Thank you for playing. The end." << endl;
    system("pause");

    return 0; } ```

D:\Programming Files\C++\vscode>cd "d:\Programming Files\C++\vscode\" && g++ Guess The Celebrity2.cpp -o Guess The Celebrity2 && "d:\Programming Files\C++\vscode\"Guess The Celebrity2
g++: error: Guess: No such file or directory
g++: error: The: No such file or directory
g++: error: Celebrity2.cpp: No such file or directory
g++: error: The: No such file or directory
g++: error: Celebrity2: No such file or directory
g++: fatal error: no input files
compilation terminated.

****NOTE THAT: DO NOT BE LIKE ME, THIS ERROR OCCURS ONLY BECAUSE I PUT SPACE ON MY FILE NAME!!! HOPE THIS HELPS!!!

您必須調用應用程序並將調用編譯為引號。 它與您的代碼完全無關:

g++ "Guess The Celebrity2.cpp" -o "Guess The Celebrity2" && "d:\Programming Files\C++\vscode\Guess The Celebrity2"

這段代碼有幾個錯誤:

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){

    int replay = 0;
    int input;

    while(int input >= replay)
    {
        //Creating variables to store
        string celebrity = "Keeves Reeves";
        string guess;

        //Prompt the user
        cout << "Guess this celebrity: He acted as John Wick" << endl;
        getline(cin, guess);


        //Check the answer by using switch statement
        if(guess == celebrity){
            cout << "Congratulations! You are right" << endl;
            input = 3;
        } else if(guess != celebrity){
            cout << "Whoops, that not the right answer..." << endl;
            cout << "If you want to try again, enter '0' to replay, enter '1' to view the answer: ";
            cin >> input;

            if(input = 1){
                cout << "The celebrity was " << celebrity << " ." << endl;
            }
        }
    }

    //Break from while loop
    cout << "Thank you for playing. The end." << endl;
    system("pause");

    return 0;
}

第一個輸入未初始化。 其次,您聲明一個變量,然后將其與重播進行比較(您覆蓋輸入)。 第三,在最后一個 if 語句中,您將 input 設置為 1,而不是比較它。

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){

    int replay = 0;
    int input = 0;

    while(input == replay)
    {
        //Creating variables to store
        string celebrity = "Keeves Reeves";
        string guess;

        //Prompt the user
        cout << "Guess this celebrity: He acted as John Wick" << endl;
        cin.ignore(); 
        getline(cin, guess);


        //Check the answer by using switch statement
        if(guess == celebrity){
            cout << "Congratulations! You are right" << endl;
            input = 3;
        } else if(guess != celebrity){
            cout << "Whoops, that not the right answer..." << endl;
            cout << "If you want to try again, enter '0' to replay, enter '1' to view the answer: ";
            cin >> input;

            if(input == 1){
                cout << "The celebrity was " << celebrity << " ." << endl;
            }
        }
    }

    //Break from while loop
    cout << "Thank you for playing. The end." << endl;
    system("pause");

    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM