为什么 iostream 头文件没有被包含?
#include <sstream>
using namespace std;
int main()
{
cout << "hi"; // error: undeclared cout
}
据我所知,sstream 类是从 iostream 类派生的,但为什么它没有自动包含在内?
#include <sstream>
using namespace std;
int main()
{
cout << "hi"; // error: undeclared cout
}
From what I have read, sstream class is derived from iostream class but why does it not get included automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于 iostream 的类与 iostream 标头不同。标准标头不必相互包含,也可以按任何顺序相互包含。如果您希望使用
的内容,则必须#include
。The
iostream
-based classes are not the same as theiostream
header. Standard headers do not have to include each other, or may include each other in any order. If you wish to use the contents of<iostream>
, you must#include <iostream>
.std::sstream
派生自std::istream
和std::ostream
。这意味着您不需要包含
或
。但是,std::cout
并未在这两个标头中定义。这就是为什么您需要另一个标头
。std::sstream
is derived from bothstd::istream
andstd::ostream
. That means you don't need to include<istream>
or<ostream>
. However,std::cout
is defined in neither of those two headers. That's why you need yet another header,<iostream>
.