- 论坛徽章:
- 0
|
刚刚在看C++对文件的操作,试用ofstream类向文件写东西。
代码是很简单的:
ofstream ofs("2.txt");
ofs.write("hellohellohello",sizeof("hellohellohello"));
ofs.close();
然后得加一个头文件 fstream.h
#include "stdafx.h"
#include "FILE.h"
#include "FILEDoc.h"
#include "FILEView.h"
#include <fstream.h>
问题是。。如果我把#include <fstream.h>放在如上所示的位置,编译就不报错。
如果把#include <fstream.h>放在 别的头文件之上,也就是这样
#include <fstream.h>
#include "stdafx.h"
#include "FILE.h"
#include "FILEDoc.h"
#include "FILEView.h"
就会报错,报的错误都是ofstream类未定义的错误,也就是fstream.h并没有加载成功,系统不识别ofstream类。
请问为什么fsream.h放在第一行就会报错呢。。。
后来又试了一下,只要放在#include "stdafx.h" 之后 就不会报错。
请各位大侠不吝赐教…感激不尽 |
|