c语言数据文件输入输出

如何吧下面的程序改成,数据输入与输出的形式
#include<iostream.h>

#include<stdio.h>

int main()

{

FILE *fout;

fout=fopen("有地效起飞重量计算.txt", "wb");

int i;

double Gwoge,Gwige,Kd[5];

cout<<"请输入Gwoge:";

cin>>Gwoge;

for(i = 0; i<5; i++)
{
cout<<"请输入Kd:";

cin >> Kd[i];

Gwige = Gwoge*Kd[i];

fprintf(fout, "%.3lf", Gwige);
}

fclose(fout);
}
老师叫改的,老师叫改的,他的原话是‘“为整理输入和计算结果及画相关曲线方便,程序应使用数据文件输入和输出文件”

1) 所谓输入输出是以计算机为主体而言的。

2) 在C语言中,所有的数据输入/输出都是由库函数完成的。因此都是函数语句。

3) 在使用C语言库函数时,要用预编译命令
    #include
将有关“头文件”包括到源文件中。

使用标准输入输出库函数时要用到 “stdio.h”文件,因此源文件开头应有以下预编译命令:

复制纯文本新窗口
    #include<stdio.h>
#include<stdio.h>

复制纯文本新窗口
    #include "stdio.h"
#include "stdio.h"

stdio是standard input&outupt的意思。

4) 考虑到printf和scanf函数使用频繁,系统允许在使用这两个函数时可不加

复制纯文本新窗口
    #include<stdio.h>
#include<stdio.h>

复制纯文本新窗口
    #include "stdio.h"
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-10-11
你试试这个
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
ofstream out("有地效起飞重量计算.txt", “wb”);//二进制写的方式
if(!out)//文件打开错误
{
cerr << "cannot open file!" << endl;
return 0;
}
int i = 0,int j = 0;
double Gwoge,Kd[5];
cout << "the file is created"<<endl;
cout << "please enter the Gwoge and 5 Kd." << endl;
while(cin >>Gwoge >> kd[i] )//循环输入,键入ctrl + z结束
{
i++;
out << Gwoge << ' ' << kd[i]<< endl;
cout << "item added!\nplease enter the Gwoge and 5 kd.(键入ctrl + z结束)" << endl;
}
out.close();

ifstream in("有地效起飞重量计算t.txt", ios::in);//创建文件读取对象
if(!in)//打开文件错误
{
cerr << "cannot open file!" << endl;
return 0;
}

while(in >>Gwoge >>kd[j])//读取文件
{
j++;
cout <<Gwoge << kd[j] << endl;
}
in.close();//关闭文件对象
return 0;
}
是写成C啊还是改程序!本回答被提问者采纳
第2个回答  2012-05-25
老师的意思是不是叫你再程序里添加文件输出和定位啊?
第3个回答  2012-05-22
没看懂你问的