【发布时间】:2016-04-13 23:31:48
【问题描述】:
我的代码是
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <stdio.h>
struct info
{
char product_name[100], Seller_Name[100], DOP[30];
int price;
}data;
void main()
{
ofstream fout("code.txt",ios::out);
fout<< "ofstream fout(\"data.dat\",ios::binary|ios::out);\n";
while(1)
{
cout << "Enter Product Name: ";
gets(data.product_name);
cout<<"Enter Seller Name: ";
gets(data.Seller_Name);
cout<<"Enter Date of Purchase: " ;
gets(data.DOP);
cout<<"Enter Price:" ;
cin>>data.price;
fout<<"strcpy(data.product_name,"<<data.product_name<<");";
fout<<"nstrcpy(data.Seller_Name,"<<data.Seller_Name<<");";
fout<<"nstrcpy(data.DOP,"<<data.DOP<<");";
fout<<"nstrcpy(data.price,"<<data.price<<");";
fout<<"fout.write((char*)&data,sizeof(info));n";
}
}
我正在开发一个软件并为其制作示例数据。所以我做了这个应用程序,所以我只需要复制语句而不必再次编写它。第一次成功了,现在不行了。
【问题讨论】:
-
您的空格键是否有问题,因为代码似乎没有任何缩进
-
你为什么要把
stdio和iosteam混在一起? -
–1 尝试发布真实代码。
-
while循环什么时候结束?
-
我认为
nstrcpy->\nstrcpy(和其他地方)。添加这些新行也会刷新缓冲区。
标签: c++ file-handling