Cannot open include file: 'fstream.h': No such file or directory

赵Andy 2009-07-15 08:14:04
请各位帮一下忙,谢谢。

#ifndef PERSONAL
#define PERSONAL

#include <fstream.h>
#include<string.h>

class Personal
{
public:
Personal();
Personal(char*,char*,char*,int,long);
void writeToFile(fstream&) const;
void readFromFile(fstream&);
void readKey();
int size() const
{
return 9+nameLen+cityLen+sizeof(year)+sizeof(salary);
}
bool operator==(const Personal& pr) const
{
return strcmp(pr.SSN,SSN)==0;
}
protected:
const int nameLen,cityLen;
char SSN[10],*name,*city;
int year;
long salary;
ostream& writeLegibly(ostream&);
friend ostream& operator<<(ostream& out,Personal& pr)
{
return pr.writeLegibly(out);
}
istream& readFromConsole(istream&);
friend istream& operator>>(istream& in,Personal& pr)
{
return pr.readFromConsole(in);
}
};
#endif
...全文
4713 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunday1118 2009-07-15
  • 打赏
  • 举报
回复
#include <fstream>
#include<string>

标准C++的写法 不知道楼主的写法是从哪里看来的 那本书可以扔之
  • 打赏
  • 举报
回复

#include <fstream>
#include<cstring>
#include<string>
using namespace std;


提倡标准..
taodm 2009-07-15
  • 打赏
  • 举报
回复
楼主需要换本新点的教材了。
lwlchristy 2009-07-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Demon__Hunter 的回复:]
C/C++ code
#include <fstream>
#include<cstring>
#include<string>
using namespace std;
[/Quote]

标准C++的写法,顶下!
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wode_dream 的回复:]
我想修代码,把strcpy修改为strcpy_s但是怎么又出现了'strcpy_s' : function does not take 2 arguments
这样应该怎么样修改
[/Quote]
char *pChar = new char[iLenth+1];
strcpy_s(pChar , iLenth+1, pSrc);
第二个参数带你分配的长度即可!
赵Andy 2009-07-15
  • 打赏
  • 举报
回复
我想修代码,把strcpy修改为strcpy_s但是怎么又出现了'strcpy_s' : function does not take 2 arguments
这样应该怎么样修改
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wode_dream 的回复:]
用strcpy_s(a,n);会出现如下提示'strcpy_s' : function does not take 2 arguments
请大家帮忙解释一下
[/Quote]
你不想修改代码的话,可以这样做:
在编译选项 C/C++ | Preprocessor | Preprocessor Definitions中,增加_CRT_SECURE_NO_DEPRECATE标记即可
赵Andy 2009-07-15
  • 打赏
  • 举报
回复
用strcpy_s(a,n);会出现如下提示'strcpy_s' : function does not take 2 arguments
请大家帮忙解释一下
pengzhixi 2009-07-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Demon__Hunter 的回复:]
C/C++ code
#include <fstream>
#include<cstring>
#include<string>
using namespace std;
[/Quote]
up,C++新标准的写法
机智的呆呆 2009-07-15
  • 打赏
  • 举报
回复

#include <fstream>
#include<cstring>
#include<string>
using namespace std;
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wode_dream 的回复:]
引用 1 楼 Demon__Hunter 的回复:
C/C++ code
#include <fstream.h>
//改成下面试试
#include <fstream>
using namespace std;


为什么?
怎么又出现了这个错误
'strcpy' was declared deprecated
请大家帮忙解释一下
[/Quote]
这是因为VS2005中认为CRT中的一组函数如果使用不当,可能会产生诸如内存泄露、缓冲区溢出、非法访问等安全问题。这些函数如:strcpy、strcat等。 对于这些问题,VC2005建议使用这些函数的更高级的安全版本,即在这些函数名后面加了一个_s的函数。这些安全版本函数使用起来更有效,也便于识别,如:strcpy_s,calloc_s等。 当然,如果执意使用老版本、非安全版本函数,可以使用_CRT_SECURE_NO_DEPRECATE标记来忽略这些警告问题。办法是在编译选项 C/C++ | Preprocessor | Preprocessor Definitions中,增加_CRT_SECURE_NO_DEPRECATE标记即可。
赵Andy 2009-07-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Demon__Hunter 的回复:]
C/C++ code
#include <fstream.h>
//改成下面试试
#include <fstream>
using namespace std;
[/Quote]
为什么?
怎么又出现了这个错误
'strcpy' was declared deprecated
请大家帮忙解释一下
lingyin55 2009-07-15
  • 打赏
  • 举报
回复
如果是用vs2008可能不能编译通过,因为fstream.h是比较旧的标准。
可以按照楼上的改下试试。
  • 打赏
  • 举报
回复
//#include <fstream.h>
#include<string.h>
#include <iostream>
using namespace std;

这样应该就可以了!
机智的呆呆 2009-07-15
  • 打赏
  • 举报
回复

#include <fstream.h>
//改成下面试试
#include <fstream>
using namespace std;

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧