Do I have to use #include lt;stringgt; beside lt;iostreamgt;?(我是否必须使用 #include lt;stringgt;在 lt;iostreamgt; 旁边?)
问题描述
我开始学习 C++,我读了一本书,书中写道我必须使用 <string>
头文件,因为字符串类型不是直接内置到编译器中的.如果我使用
我可以使用字符串类型.
I started learning C++ and I read a book which writes that I must use the <string>
header file because the string type is not built directly into the compiler.
If I use the <iostream>
I can use the string type.
如果我包含
标头,当我想使用字符串类型时,是否必须包含
标头?为什么?有什么区别吗?
Do I have to include the <string>
header when I want to use the string type if I included the <iostream>
header? Why? Is there some difference?
推荐答案
是的,您必须包含您使用的内容.标准头相互包含并不是强制性的(IIRC 除外).它现在可能可以工作,但在不同的编译器上可能会失败.
Yes, you have to include what you use. It's not mandated that standard headers include one another (with a few exceptions IIRC). It might work now, but might fail on a different compiler.
在您的情况下,显然
包括
,直接或间接,但不要依赖它.
In your case, apparently <iostream>
includes <string>
, directly or indirectly, but don't rely on it.
这篇关于我是否必须使用 #include <string>在 <iostream> 旁边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我是否必须使用 #include <string>在 <iostream> 旁边?


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01