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

C++文件输入输出

时间:2016-04-29 23:46:36      阅读:420      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>  //有些系统里面可以省略此头文件
#include <fstream>
#include <string>

int main()
{
    using namespace std;

    string filename;

    cout << "please enter name for new file" << endl;
    cin >> filename;

    ofstream  fout( filename.c_str());

    fout << "For your eyes only! \n";
    cout << "Enter your secret number: ";
    string secret;
    cin >> secret;
    fout <<"Your secret number is " <<secret << endl;
    fout.close();

    ifstream fin(filename.c_str());
    cout << "Here are the contents of " << filename << ":\n";
    char ch;
    while (fin.get(ch))
    {
        cout << ch;
    }

    cout << "Done!\n";

    fin.close();
    return 0;
}

 

C++文件输入输出

标签:

原文地址:http://www.cnblogs.com/wujing-hubei/p/5447699.html

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