无法在Code :: Blocks SDL程序中包含C ++标头?

时间:2016-10-28 10:53:45

标签: c++ sdl

我正在尝试执行一个简单的SDL程序。我按照教程here中的说明进行操作。 程序使用C头(stdlib.h for printf())按预期构建和执行。但是当我尝试使用iostream(对于cout)时,它会引发错误。构建消息说"致命错误:iostream:没有这样的文件或目录"。

如何在SDL2中使用C ++功能?它甚至不允许我使用bool或类。当我使用C函数和数据类型时,程序执行得很好。

我有 Code :: Blocks 16.01 SDL 2.05

我是SDL的新手和所有这些东西,请不要粗鲁。我知道问题对你们来说可能听起来很愚蠢。我在这里搜索了解决方案,但没有找到与此相关的任何相关答案。如果SDL安装不正确,请指出正确的步骤。如果有人帮我解决这个问题,我将不胜感激!感谢。

抱歉英语不好,如果问题听起来不清楚,请发表评论。

P.S:这段代码对我来说是因为我注释掉了C ++部分。

#include<SDL.h>
#include<stdlib.h>
//#include<iostream>
//using namespace std;

const int screen_width=250;
const int screen_height=500;

int main(int argc,char* args[])
{
SDL_Window *window=NULL;
//SDL_Window is new data type. Always initialize pointer to NULL.

SDL_Surface* screenSurface=NULL;
//SDL_Surface is new data type. Surface is just a 2d image

//cant call any SDL function without initializing it before..

if(SDL_Init(SDL_INIT_VIDEO)<0)
{

}
//cout<<"SDL could not be initialized! Error:"<<SDL_GetError();

else
{
    //creating a window

    window=SDL_CreateWindow("SDL Tutorial",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,screen_width,screen_height,SDL_WINDOW_SHOWN);
    //just a error check again. make it habit to check for error always!!
    if(window==NULL)
    {
    //cout<<"Sorry window could not be created!"<<SDL_GetError();
    }

    else
    {
        //get window surface. surface of window of type SDL_Window is returned to type of surface of SDL_Surface
        screenSurface=SDL_GetWindowSurface(window);

        //fill the surface
        SDL_FillRect(screenSurface,NULL,SDL_MapRGB(screenSurface->format,0xFF,0xFF,0xFF));

        //update the surface!, you always need to update surface !!

        SDL_UpdateWindowSurface(window);

        //wait for defined amount of time! time is in millisecs

        SDL_Delay(2000);

        //destroy window
        SDL_DestroyWindow(window);

        //quite SDl subsystems

        SDL_Quit();

    }

}
return 0;
}

0 个答案:

没有答案
相关问题