从GCC随附的标头中获取语法错误

时间:2019-04-21 19:39:37

标签: c++

我正在使用Windows.h中的Sleep,当我进行编译时,出现了这些错误。我尝试使用Google搜索,但一无所获。我也不希望GCC的包含文件中有这样的问题。谁能告诉我这些错误可能来自什么。

edit:虽然有很多此类代码尚未完成,但希望对其进行部分测试。我主要只是想弄清楚这种类型的螺丝钉,因为我不知道从哪里开始。

>g++ -o test.exe main.cpp

In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:65:0,
                 from main.cpp:3:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:14:8: error: expected unqualified-id before string constant
 extern "C" {
        ^
In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:65:0,
                 from main.cpp:3:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected '}' before end of line
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected unqualified-id before end of line
C:/TDM-GCC-64/x86_64-w64-mingw32/include/excpt.h:128:18: error: expected declaration before end of line

这是主要内容:

#include "program/skull_ascii.h"
#include "Player.h"
//#include "Building.h"

#include "Windows.h"
#include <iomanip>
#include <stdlib.h>
#include <string>

//prototypes
void intro();
void cityScene(Player*);
Player* getUserInfo();
void scroll(std::string text);

int main(){
    intro(); //flashy ascii text intro
    player* user = getUserInfo();
    cityScene(user);

}


void intro(){ //not done tweaking
    system("mode con:cols=81 lines=30");
    system("color 02");
    skull_title();
    Sleep(1000);
    for(int i = 1; i < 15; i++){
        system("color 04");
        Sleep(i*i / 2);
        system("color 02");
        Sleep(i*i);
    }   
    system("color 04");
    system("pause");
    system("cls");
    system("mode con:cols=120 lines=30");
}

Player* getUserInfo(){ //not done, just enough to test
    player* user = new Player("test", 56);
    return user;
}

void cityScene(Player* user){ //not close to finished, but shouldn't cause any issue
    std::string prompt = "arbitrary text"; // will print out with other function    

    system("pause");
    system("cls");

    std::cout << "what do you want to do?: \n"
    std::cout << "\t1.Just relax its not that important\n";
    std::cout << "\t2.scavenge the apartment for items\n";
    std::cout << "\t3.Leave immediately, there's no time left\n";
    std::cout << ":";
}

void scroll(std::string text){
    for(int i = 0; i < text.length(); i++){
        std::cout << text[i];
        Sleep(200);
        if(i%45 == 0) std::cout << "\n"; 
    }
}

播放器类是一个凌乱的容器atm,尚未完成 这是播放器类:


#pragma once

#include <string>
#include <list>
#include <iostream>
#include "Item.h"

class Player{

    std::string name;
    int age;

    std::list<Item> inventory;

    public:

    Player(std::string n, int a){
        this->name = n;
        this->age = a;
    }

    /*  F-name: updateScreen()
        params: none
        return: void
        purpos: updates the play screen with current player information
    */void update(){
        system("cls"); // clear screen
        std::cout << "NAME:" << name << "  |\
            AGE:XXX  | \
            WEAPONS: weapon 1, weapon2  | \
            PACK_WEIGHT:XXXXXXXKgs  | \
            PARTY: name1, name2, name3, name4  | \
            LOCATION:  big city"; 
    }



    /*  
    F-name: addItem()
    params: item object to add
    return: void
    purpos: adds an item to the inventory list
    */ void addItem(Item newItem){}

#pragma once

#include <iostream>
#include <string>


class Item{
    std::string name;
    std::string desc;


    public:

    Item(){ 
        name = "void";
        desc = "void";
    }

    Item(const Item& copy){
        this->name = copy.name;
        this->desc = copy.desc;

    }

    Item(std::string n, std::string d){
        name = n;
        desc = d;
    }

    ~Item(){}


    friend std::ostream& operator<< (std::ostream& out, const Item& thing){
        out << thing.name;
        return out;
    }


    void setName(std::string n){name = n;}
    void setDesc(std::string d){desc = d;}

    std::string getName(){return name;}
    std::string getDesc(){return desc;}

};

1 个答案:

答案 0 :(得分:1)

Player中的Player.h类定义未正确关闭。您忘记添加:

};

最后。现在,这将导致您包含的下一个标头导致编译错误。