为什么g ++找不到iostream.h? [英] Why can't g++ find iostream.h?

查看:1120
本文介绍了为什么g ++找不到iostream.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解如何从命令行使用g ++和(最终)Clang在Ubuntu上编译C ++程序。



我发现了一个网页,解释MakeFiles我按照他们的指示。 http://mrbook.org/tutorials/make/



我将这四个示例文件下载到自己的目录中。




  • main.cpp

  • hello.cpp

  • factorial.cpp

  • functions.h



然后我继续前进,并举例说明如何手动编译没有MakeFile。

  g ++ main.cpp hello.cpp factorial .cpp -o hello 

当我从上面运行命令时,从g ++收到以下错误:

  main.cpp:1:22:fatal错误:iostream.h:没有这样的文件或目录
编译终止。
hello.cpp:1:22:fatal错误:iostream.h:没有这样的文件或目录
编译终止。

我唯一的编写c ++的经验是使用一个IDE,如VS C ++ Express或CodeBlocks。是不是编译器应该知道iostream.h是什么,在哪里找到它?



如何摆脱这个错误,所以程序willl编译? p>

感谢您的帮助。

解决方案

在ISO标准化C ++语言之前,头文件名为< iostream。 h> ,但是当C ++ 98标准发布时,它被重命名为< iostream> c> .h )。更改代码以使用 #include< iostream> ,而应该编译。



使用命名空间std; 语句为每个源文件添加一个(或前缀每个对iostream函数/对象的引用 std :: specifier),因为命名空间在预标准化的C ++中不存在。 C ++ 98将标准库函数和对象放在 std 命名空间内。


I'm trying to understand how to compile C++ programs from the command line using g++ and (eventually) Clang on Ubuntu.

I found a webpage which explains MakeFiles and I am following their directions. http://mrbook.org/tutorials/make/

I downloaded the four example files into their own directory.

  • main.cpp
  • hello.cpp
  • factorial.cpp
  • functions.h

I then went ahead and ran their example of how to manually compile without a MakeFile.

g++ main.cpp hello.cpp factorial.cpp -o hello

When I ran the command from above, I received the following error from g++:

main.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
hello.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.

My only experience with writing c++ is using an IDE such as VS C++ Express or CodeBlocks. Isn't the compiler supposed to know what iostream.h is and where to find it?

How do I get rid of this error so the program willl compile?

Thanks for any help.

解决方案

Before the C++ language was standardized by the ISO, the header file was named <iostream.h>, but when the C++98 standard was released, it was renamed to just <iostream> (without the .h). Change the code to use #include <iostream> instead and it should compile.

You'll also need to add a using namespace std; statement to each source file (or prefix each reference to an iostream function/object with a std:: specifier), since namespaces did not exist in the pre-standardized C++. C++98 put the standard library functions and objects inside the std namespace.

这篇关于为什么g ++找不到iostream.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆