• C++文件读写,写文件两个回车结束


    #include <iostream>
    #include <fstream>
    #include<stdlib.h>
    #include <string>//not <string.h>

    using namespace std;

    int main()
    {
    ifstream in_stream;//read file
    ofstream out_stream;//write file

    string quit = " ";
    while(quit != "quit")
    {
    //output the advice that arised by the last person
    in_stream.open("D:\\代码和工程\\Visual Studio 2010\\Projects\\homework5_5\\advice.txt");

    if(!in_stream)
    {
    cout << "Can not open the file!"<<endl;
    abort();//exit the program <stdlib.h>
    }

    char str[80];
    cout << "The advice is " << endl;
    while(!in_stream.eof())
    {
    in_stream.getline(str,sizeof(str));

    cout << str << endl ;
    }

    in_stream.close();

    //input the new person's advice and record it
    cout << "Please enter your advice by pressing Enter key twice." << endl;
    out_stream.open("D:\\代码和工程\\Visual Studio 2010\\Projects\\homework5_5\\advice.txt");
    if(!out_stream)
    {
    cout << "Can not open the file!"<<endl;
    abort();//exit the program <stdlib.h>
    }

    char c, last = ' ';
    while(1)
    {
    c = cin.get();
    if (c == 10 && last == 10)
    {
    break;
    }
    last = c;
    out_stream << c;
    }

    out_stream.close();
    cout << "Please press any key to continue.Press 'quit' to quit";
    cin >> quit;
    cout << endl;
    }


    system("pause");
    return 0;
    }

  • 相关阅读:
    UICollectionView的简单使用(一)
    天气预报接口IOS版OC:SmartWeather API中key的计算方法
    IOS下Base64加密
    IOS下DES加密
    IOS的URL中文转码
    CTE Recursion Performance
    走过而立之年的Coder
    iOS多线程编程之锁的理解
    iOS设置PCH文件
    程序员:伤不起的三十岁
  • 原文地址:https://www.cnblogs.com/syxxlove/p/2800622.html
Copyright © 2020-2023  润新知