我必须使用#include< string>在< iostream>旁边 [英] Do I have to use #include <string> beside <iostream>?
问题描述
我开始学习C ++,我读了一本书,书中写道,我必须使用< string>
头文件,因为字符串类型不是直接构建到编译器中。
如果我使用< iostream>
我可以使用字符串类型。
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.
如果我包括< iostream>
,当我想使用字符串类型时,包括< string> 标题?为什么?有什么区别吗?
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.
在您的情况下,显然< iostream>
包括< string>
,直接或间接,但不要依赖它。
In your case, apparently <iostream>
includes <string>
, directly or indirectly, but don't rely on it.
这篇关于我必须使用#include< string>在< iostream>旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!