1. 程式人生 > >c++ 文件操作

c++ 文件操作

mode getline price AI ring OS outfile () mobile

//
//  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++ 文件操作