I/O compile

write-file


//

#include "stdafx.h"
#include<iostream>
#include <string>
#include<stdio.h>
#include<cstring>
#include<array>
#include<fstream>

using namespace std;


//ostream define cout ,display on the screen
//fstream define fout ,display in the file

int main()
{
    ofstream fout;
    fout.open("first.txt");


    string automobile;
    int year;
    double sprice, dprice;
    cout << "enter the make and model of automo\t\n";
    cin >> automobile;
    cout << "\n\tenter the mobile year\n\t";
    cin >> year;
    cout << "enter the price\n";
    cin >> sprice;
    dprice = 0.879*sprice;

    cout << fixed;//yong yibande fangshishuchufudianshu erbushikexuejishufa
    cout.precision(2);
    cout.setf(ios_base::showpoint);
    cout << "make and model\t" << automobile << endl;
    cout << "year\t" << year << endl;
    cout << "pro price\t" << sprice << endl;
    cout << "the price\t" << dprice << endl;

    fout << fixed;//yong yibande fangshishufhufudianshu erbushikexuejishufa
    fout.precision(2);
    fout.setf(ios_base::showpoint);
    fout << "make and model\t" << automobile << endl;
    fout << "year\t" << year << endl;
    fout << "pro prife\t" << sprice << endl;
    fout << "the prife\t" << dprice << endl;

    fout.close();
    return 0;




}

read-file

int main()
{
    //first one-check number
    ifstream fin;
    fin.open("first.txt");

    if (!fin.is_open())
    {
        cout << "fuckyou\t\n";
        exit(EXIT_FAILURE);
    }

    double n;
    int count = 0;
    while (fin>>n)
    {
        count++;
        cout << n<<endl;
        fin >> n;
    }

    if (fin.eof())//最后一个fin读到 EOF ,eof()return ture
        cout << "reach end\n";
    else if (fin.fail())//类型不匹配
        cout << "data dismatch\n";
    else
        cout << "unknown reason\n";


    cout << count;
    //second one-check word
    return 0;




}

my-own findword

int main()
{
    //first one-check number
    ifstream fin;
    fin.open("first.txt");

    if (!fin.is_open())
    {
        cout << "fuckyou\t\n";
        exit(EXIT_FAILURE);
    }

    char n;
    int count = 0;
    while (fin.get(n))
    {
        count++;
        cout << n;
        fin.get(n);
    };

    if (fin.eof())//最后一个fin读到 EOF ,eof()return ture
        cout << "reach end\n";
    else if (fin.fail())//类型不匹配
        cout << "data dismatch\n";
    else
        cout << "unknown reason\n";


    cout << count;
    //second one-check word
    return 0;




}

shit,the result is wrong

but i cannot figure it out right now!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值