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> 旁边?
基础教程推荐
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- c++ STL设置差异 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
