⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io20_6.06.c

📁 C++ PRIME书中的原代码,看本书时可以学习的例子.
💻 C
字号:
// #include <fstream>
#include <fstream.h>
#include "WordCount.h"

/** 
 **
 ** as is the case with io20_6.02.c, WordCount.C
 ** must also be compiled with this program ...
 **
 stanl@john:d.ch20 258 : cat word.out

 <2> Renoir
 <7,12>  <34,18>  

 stanl@john:d.ch20 259 : a.out

 Read in: <2> Renoir
 <7,12>  <34,18>  

 stanl@john:d.ch20 260 : cat word.out

 <2> Renoir
 <7,12>  <34,18>  

 <2> Renoir
 <7,12>  <34,18>  
 **
 **/

int main()
{
    WordCount wd;

    fstream file;
    // ios is preStandard class name
    // file.open( "word.out", ios_base::in );
    file.open( "word.out", ios::in );

    if ( ! file ) {
	 cerr << "oops! unable to open input file word.out\n";
	 return -1;
    }

    file >> wd;
    file.close();

    cout << "Read in: " << wd << endl;

    // ios_base::out would discard current data
    // file.open( "word.out", ios_base::app );
    file.open( "word.out", ios::app );

    if ( ! file ) {
         cerr << "oops! unable to open input file ``word.out''\n";
         return -1;
    }

    file << endl << wd << endl;
    file.close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -