page226

// page226.cpp : 定义控制台应用程序的入口点。
//C++ 面向对象程序设计


//从用户指定的文件读取3个数,求和,并将结果写入用户指定的另一个文件


#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <fstream>


int main()
{
using namespace std ;
int a ;
char in_file_name[16], out_file_name[16];
ifstream in_stream ;
ofstream out_stream;


cout << " I will sum three numbers taken from an input\n"
<< " file and write the sum to output file .\n";
cout << " Enter the input file name (maximum of 15 characters):\n";
cin >> in_file_name ;
cout << " Enter the input file name (maximum of 15 characters):\n";
cin >> out_file_name;
cout << " I will read numbers from the filev "
<< in_file_name << " and\n"
<< " place the sum in file "
<< out_file_name << endl ;


in_stream.open(in_file_name);
if (in_stream.fail())
{
cout << " input file opening failed.\n";
exit(1);
}

out_stream.open(out_file_name);
if(out_stream.fail())
{
cout << " ouput file opening failed .\n";
exit(1);
}
int frist , second ,third;
in_stream >> frist >> second >> third ;
out_stream << " The sum of first 3\n"
<< " numbers in " << in_file_name << endl
<< " is " << (frist + second + third)
<< endl ;


in_stream.close();
out_stream.close();
cout << " End of Program.\n";


cin >> a ;
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值