zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    关于append,appendTo,prepend,prependTo的区别
    CSS3 pointer-events:none应用举例及扩展
    jQuery插件的开发(一)
    css3 appearance在iphone上面的问题
    最短路系列
    最小生成树系列
    最大流问题
    poj_1050
    NO TIME, BUT COURAGE, BUT BEAUTY(汇编小程序)
    ubuntu软件与使用
  • 原文地址:https://www.cnblogs.com/syxxlove/p/2800622.html
Copyright © 2011-2022 走看看