读书人

fstream.h中已经包孕iostream.h了为

发布时间: 2012-10-20 14:12:48 作者: rapoo

fstream.h中已经包含iostream.h了,为什么...

C/C++ code
#include <fstream>using namespace std;int main(){    int a[10];    ofstream outfile;    outfile.open("student.txt",ios::app);    if(!outfile)    {        cerr<<"open error!"<<endl;        exit(1);    }    cout<<"enter 10 integer numbers:"<<endl;    for(int i=0;i<10;i++)    {        cin>>a[i];        outfile<<a[i]<<" ";    }    outfile.close();    return 0;}

fstream.h中已经包含iostream.h了,为什么还提示错误:
'cerr' : undeclared identifier
'cout' : undeclared identifier
...
加上#include <iostream>就对了。

[解决办法]
探讨
C/C++ code

#include <fstream>
using namespace std;
int main()
{
int a[10];
ofstream outfile;
outfile.open("student.txt",ios::app);
if(!outfile)
{
cerr<<"open error!"<<end……

[解决办法]
用什么包含什么, 不要依赖头文件的依赖, 你只要做自己想做的, 头文件宏会帮你防止重复引入.

读书人网 >C++

热点推荐