问题描述
我开始学习 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> 旁边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!