文件的读写

来源:互联网 发布:mac系统下载栏不是扇形 编辑:程序博客网 时间:2024/05/20 21:19
**#include <iostream>#include <fstream>using namespace std;void save_to_file(){ofstream outfile("f2.dat");if(! outfile){cerr<<"open f2.dat error!"<<endl;exit(0);}    char c[80];    cin.getline(c,80);    for(int i=0;c[i]!=0;i++) {        if (c[i] >= 65 && c[i] <= 90 || c[i] >= 97 && c[i] <= 122) {            outfile.put(c[i]);            cout << c[i];        }    }        cout<<endl;        outfile.close();}void get_from_file(){    char ch;    ifstream infile("f2.dat",ios::in);    if(! infile)    {        cerr<<"open f2.dat error!"<<endl;        exit(0);    }    ofstream outfile("f3.dat");    if(! outfile)    {cerr<<"open f3.dat error!"<<endl;    exit(0);    }    while(infile.get(ch))    {        if(ch>=97&&ch<=122)ch=ch-32;        outfile.put(ch);        cout<<ch;    }    cout<<endl;    infile.close();    outfile.close();}int main(){   save_to_file();    get_from_file();    return 0;}#include <iostream>#include <fstream>using namespace std;void save_to_file(){ofstream outfile("f2.dat");if(! outfile){cerr<<"open f2.dat error!"<<endl;exit(0);}    char c[80];    cin.getline(c,80);    for(int i=0;c[i]!=0;i++) {        if (c[i] >= 65 && c[i] <= 90 || c[i] >= 97 && c[i] <= 122) {            outfile.put(c[i]);            cout << c[i];        }    }        cout<<endl;        outfile.close();}void get_from_file(){    char ch;    ifstream infile("f2.dat",ios::in);    if(! infile)    {        cerr<<"open f2.dat error!"<<endl;        exit(0);    }    ofstream outfile("f3.dat");    if(! outfile)    {cerr<<"open f3.dat error!"<<endl;    exit(0);    }    while(infile.get(ch))    {        if(ch>=97&&ch<=122)ch=ch-32;        outfile.put(ch);        cout<<ch;    }    cout<<endl;    infile.close();    outfile.close();}int main(){   save_to_file();    get_from_file();    return 0;}**

随机访问二进制数据文件

0 0
原创粉丝点击