问题描述
在此代码中,如果我编写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;
}
推荐答案
#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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!