iostream.h和iostream [英] iostream.h vs iostream

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

问题描述

在此代码中,如果我编写iostream.h,它将为我提供输出而没有任何错误,但是如果我仅编写
iostream代替iostream.h,那么我将不得不使用 namespace std 语句,那么iostream.h头文件的用途是什么?

In this code if i write iostream.h then it will give me output without any error, but if i write only
iostream in place of iostream.h then i will have to use namespace std statement ,then what is the use of iostream.h headerfile ?

#include <iostream>
#include <conio.h>

//using namespace std;
int main()
{
    //std::cout<<"Hello";
    
    cout<<"Hello";
    getch();
    return 0;
}

推荐答案

您说的话就像命名空间限定的名称或"using namespace std"一样. :-)

太好了!您认为名称空间是为什么设计的?

此处详细说明了无扩展""<iostream>"和"<iostream.h>"的背景: http: //members.gamedev.net/sicrane/articles/iostream.html [ ^ ].

-SA
You say it like namespace-qualified names or "using namespace std" is something bad. :-)

This is good! What do you think name spaces are designed for?

The background on "extensionless" "<iostream>" vs. "<iostream.h>" is explained in detail here: http://members.gamedev.net/sicrane/articles/iostream.html[^].

—SA


#include <iostream.h>

是iostream东西现在已过时的头文件.

现在,您只需添加

is the now obsolete header file for the iostream stuff.

Now, you juste need to include

#include <iostream>



不带.h的iostream是iostream的标准头.

所有新的标准c ++头文件都使用.h-less名称.



the iostream without the .h is the standardized header for the iostreams.

All new standard c++ header use the .h-less names.

#include <vector>
#include <algorithm>
...



今天,所有(大多数?)STL和标准C ++代码都在std名称空间中.
您可以使用



Today all (most?) STL and standard C++ code are in the std namespace.

You can either use

using namespace std;



如果编译器(?)在全局名称空间中找不到声明,则让编译器(?)知道在std名称空间中查找. (可能是一个不好的措词).

或仅在STL和标准c ++函数和方法之前使用std::.

这样你就会有



to let the compiler (?) know to look in the std namespace if it cannot find the declaration in the global namespace. (probably a bad wording).

or just use std:: in front of the STL and standard c++ functions and method.

so you''ll have

...
using namespace std;
cout << "hello" << endl;







or

...
std::cout << "hello" << std::end;


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

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