大家帮 忙看一下啊

CloudOfFly 2005-06-06 07:10:41
我写了一个数据库程序
#include<fstream.h>

struct Date
{
int iMonth, iDay, iYear;
};

struct Product
{
int iPartNumber;
char szName[80];
double dPrice;
};

struct Customer
{
int iID;
char szName[50];
char szAddress[50];
char szCity[20];
char szState[20];
char szZip[9];
};

void main()
{
Date dt = {6, 10, 92};
Product prod = {122, "Vegamatic",19.95};
Customer cust = {15, "Seymore Hoskins", "300 Oak St",
"Boring", "Oregon", "97203"};
ofstream datafile("ata.dat", ios::binary);
datafile.write((char *)&dt, sizeof dt);
datafile.write((char *)&prod, sizeof prod);
datafile.write((char *)&cust, sizeof cust);
}

然后我写了一个程序读 它生成的数据库文件 ata.dat

#include<iostream.h>
#include<fstream.h>
#include<main.cpp>//是上面那个程序文件
int main()
{
ifstream is("data.dat", ios::binary|ios::nocreate);
if(is)
{
is.read((char*)&dt, sizeof(dt));
is.read((char*)&prod, sizeof(prod));
out<<prod.szName<<endl;
}
else
{
cout<<"ERROR:Cannot open file 'data.dat'."<<endl;
}
}



Compiling...
main1.cpp
D:\MyProjects\exmple4\main1.cpp(3) : fatal error C1083: Cannot open include file: 'main.cpp': No such file or directory
Error executing cl.exe.

exmple4.exe - 1 error(s), 0 warning(s)
却出现如上错误

请各位大哥门帮我看看 错在那里
小弟感激不尽
...全文
120 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zdy_8212 2005-06-06
  • 打赏
  • 举报
回复
为什么要调用main.cpp,包含的是头文件。还有你上面的代码第一个是ata,第二个是data
jingyueid 2005-06-06
  • 打赏
  • 举报
回复
#include <main.cpp>
??????


将main.cpp中用到的函数声明都放到一个.h头文件中,然后让你下面的那个程序来包含这个头文件。
.o文件在连接的时候会自动查找外接函数。

同时不要用<>要用""符号,在当前目录寻找该文件。
「已注销」 2005-06-06
  • 打赏
  • 举报
回复
D:\MyProjects\exmple4\main1.cpp(3) : fatal error C1083: Cannot open include file: 'main.cpp': No such file or directory
#include "main.cpp"试试。。
tlzhu 2005-06-06
  • 打赏
  • 举报
回复
#include<main.cpp> 的尖括号改为“”试试。
还有一个问题,这样你的程序有两个main()了,能行吗?

65,189

社区成员

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

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