Getting Started -> Using (C ++ Library) IFSTREAM Read File Data

zhaozj2021-02-17  52

Collection original

// AWZZZ @ 2002

// Getting Started -> Using (C ) IFSTREAM Read File Data

// Apo-> Using iFstream.

// Accident Project of use IFStream. (C iostream library)

/ *

Reference: http://www.cplusplus.com/ref/iostream/iFstream/

Description

IFStream Class Provides A Street Interface To Read Data from Files.

THE CLASS MANTAINS INTERLY (Privately) a Pointer to a filebuf Object

In Charge of the Intertion with the file. This Pointer Can Be

Obtained / Modified by Calling Member Rdbuf.

The File to Be Processed Can Be Specified As a Parameter for T

Constructor or by calling member open.

After a file is processed it can be closed by calling member close.

In this case the file stream may be used to open another file.

MEMBER IS_OPEN CAN BE Used to Determine Wether The Stream Is Currently

Operating on a file or not.

Please refer to Parent Classes for more details on information mantained

By an iFstream Object.

* /

// Use (C ) ifstream read file data

// Simple Example

#include

#include

Using namespace std;

#ifdef Win32

#define test_file "c: //tmp/test.txt"

#ELSE

#define test_file "/tmp/test.txt"

#ENDIF

Void get ()

{

// ifstream IFS;

//ifs.open; Test_File

ifstream IFS (Test_File);

// while (ifs.good ()) cout << (char) ifs.get (); // simple

While (ifs.good ()) {

CHAR CH = 0;

// CH = ifs.get ();

IFS.get (CH);

Cout << CH;

}

IFS.Close ();

}

Void getLine ()

{

// ifstream IFS;

//ifs.open; Test_File

ifstream IFS (Test_File);

WHILE (ifs.good ())

{

CHAR BUF [1024] = {0};

IFS.GetLine (BUF, SIZEOF (BUF));

Cout << BUF << Endl;

}

IFS.Close ();

}

Int main (int Argc, char * argv [])

{

Get ();

Getline ();

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-28691.html

New Post(0)