码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 文件操作

时间:2018-03-01 00:30:45      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:get   stream   auto   fstream   created   inf   insert   line   post   

 

//
//  main.cpp
//  test
//
//  Created by zzy on 2018/2/26.
//  Copyright ? 2018年 zzy. All rights reserved.
//

#include <iostream>
#include <fstream>
using namespace std;
int main() {
    // insert code here...
    char automobile[50];
    int year;
    double a_price,b_price;
    
    ofstream outFile;
    outFile.open("carinfo.txt");
    
    cout<<"Enter the make and model of automabile:";
    cin.getline(automobile, 50);
    cout<<"Enter the mobile year:";
    cin >>year;
    cout<<"Enter the oringinal asking price: ";
    cin>>a_price;
    b_price=0.913 * a_price;
    
    cout<<fixed;
    cout.precision(2);
    cout.setf(ios_base::showpoint);
    cout<<"Make and mobile:"<<automobile<<endl;
    cout<<"year:"<<year<<endl;
    cout<<"Was asking $"<<a_price<<endl;
    cout<<"Now asking $"<<b_price<<endl;
    
    outFile<<fixed;
    outFile.precision(2);
    outFile.setf(ios_base::showpoint);
    outFile<<"Make and mobile:"<<automobile<<endl;
    outFile<<"year:"<<year<<endl;
    outFile<<"Was asking $"<<a_price<<endl;
    outFile<<"Now asking $"<<b_price<<endl;
    outFile.close();
    return 0;
    
}

 

c++ 文件操作

标签:get   stream   auto   fstream   created   inf   insert   line   post   

原文地址:https://www.cnblogs.com/bohat/p/8486257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!