I/O compile

来源:互联网 发布:java pkcs10 公钥 编辑:程序博客网 时间:2024/06/15 10:25

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 fileint 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!!!!!

原创粉丝点击