C语言 由于#include<graphics.h> 导致的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27839752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:40:49  来源:igfitidea点击:

Error due to #include<graphics.h>

cgraphicsinclude

提问by Ayushi Jha

I am trying to compile a program which includes the graphics.hheader file for C. I have added the graphics.hand winbgim.hheader files in the include folder and also libbgi.ato lib folder.

我正在尝试编译一个包含graphics.hC 头文件的程序。我在 include 文件夹和lib 文件夹中添加了graphics.hwinbgim.h头文件libbgi.a

Just for testing, I made a simple hello world program and included the graphics.hheader file.

只是为了测试,我做了一个简单的hello world程序并包含了graphics.h头文件。

But on compiling I got the following error:

但是在编译时出现以下错误:

In file included from firstc.c:2:0: c:\mingw\bin../lib/gcc/mingw32/4.7.1/../../../../include/graphics.h:30:59: fatal error: sstream: No such file or directory compilation terminated.

在 firstc.c:2:0 包含的文件中:c:\mingw\bin../lib/gcc/mingw32/4.7.1/../../../../include/graphics.h:30 :59: 致命错误: sstream: 没有终止此类文件或目录编译。

I tried to search in other forums as well, where the same question had been asked, but could not get an answer.

我也尝试在其他论坛中搜索,也有人问过同样的问题,但无法得到答案。

Another question, I came across other graphic options for C and C++ like openGL and DirectX. Should I learn these instead of graphics.h?

另一个问题,我遇到了 C 和 C++ 的其他图形选项,如 openGL 和 DirectX。我应该学习这些而不是 graphics.h 吗?

回答by Lundin

graphics.his a non-standard header. Most likely it refers to the old BGI graphics library of the Turbo C DOS compiler. It will only work on that particular compiler. And of course DOS is a completely obsolete OS nowadays.

graphics.h是一个非标准的标题。它很可能是指 Turbo C DOS 编译器的旧 BGI 图形库。它只适用于那个特定的编译器。当然,DOS 现在是一个完全过时的操作系统。

If you are interested in 3D graphics programming, then OpenGL and/or DirectX are indeed better, modern alternatives, supported by many compilers.

如果您对 3D 图形编程感兴趣,那么 OpenGL 和/或 DirectX 确实是更好的现代替代品,受到许多编译器的支持。

回答by Panos Kal.

If you try to compile the source code with including “graphics.h” in code::blocks IDE you have to setup winBGImlibrary.

如果您尝试在 code::blocks IDE 中包含“graphics.h”来编译源代码,则必须设置winBGIm库。

  • Download WinBGImfrom http://winbgim.codecutter.org/or use (direct link)
  • Extract it.
  • Open graphics.h, go to line 302change int right=0to int top=0
  • Copy graphics.hand winbgim.hfiles in include folder of your compiler directory.
  • Copy libbgi.ato lib folder of your compiler directory
  • In code::blocks open Settings>> Compiler and debugger>> linker settings
  • Click Addbutton in link libraries part, browse and select libbgi.afile
  • In right part (ie. other linker options) paste commands
    -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  • Click Ok

  • WinBGImhttp://winbgim.codecutter.org/下载或使用(直接链接
  • 提取它。
  • 打开graphics.h,转到行302更改int right=0int top=0
  • 在编译器目录的包含文件夹中复制graphics.hwinbgim.h文件。
  • 复制libbgi.a到编译器目录的 lib 文件夹
  • 在代码中::块打开Settings>> Compiler and debugger>>linker settings
  • 单击Add链接库部分中的按钮,浏览并选择libbgi.a文件
  • 在右侧(即其他链接器选项)粘贴命令
    -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  • 点击 Ok

You can also check this videotutorial.

您还可以查看此视频教程。

Compiler options

编译器选项

回答by Pramesh Pudasaini

When you're compiling a C source code having graphics.h header file, you'll need to change the file extension to .cpp. Without doing that, you'll get “fatal error: sstream : no such file directory” error.

当您编译具有 graphics.h 头文件的 C 源代码时,您需要将文件扩展名更改为 .cpp。如果不这样做,您将收到“致命错误:sstream:没有这样的文件目录”错误。

So, simply change the .c extension to .cpp. Here's a step-by-step procedureto compiling graphics.h source code if you're using Code::Blocks to run the code.

因此,只需将 .c 扩展名更改为 .cpp。如果您使用 Code::Blocks 运行代码,这里有一个编译 graphics.h 源代码的分步过程

回答by Tushar Sharma

The sstream error occurs only when you are compiling using gcc not g++ , try using g++ or converting the program to c++ , as far as i know ( since i'm new to this language but i've faced this error before ) so goodluck with that

sstream 错误仅在您使用 gcc 而不是 g++ 进行编译时发生,据我所知,尝试使用 g++ 或将程序转换为 c++ 时(因为我是这种语言的新手,但我以前遇到过这个错误)所以祝你好运那

回答by Hymanw11111

If top answer doesn't work, and you are getting:

如果最佳答案不起作用,您将得到:

  • error: narrowing conversion of 'x' from 'int' to 'short unsigned int'

  • your graphics window just doesn't appear

    following thistutorial and using the bug fixed headers/libraries (winBGIm(bug-free).rar) in the provided winBGIm source link, worked for me in Windows 10.

  • error: narrowing conversion of 'x' from 'int' to 'short unsigned int'

  • 你的图形窗口没有出现

    遵循教程并winBGIm(bug-free).rar在提供的 winBGIm 源链接中使用修复了错误的标头/库 ( ),在 Windows 10 中对我来说有效。

Mirrorto winBGIm(bug-free_.rar)

镜像winBGIm(bug-free_.rar)

compiling with: g++ example.cpp -Wall -m32 -std=c++11 -pedantic -g -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -o example.exe

编译: g++ example.cpp -Wall -m32 -std=c++11 -pedantic -g -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -o example.exe