basic_fstream 클래스
Describes an object that controls insertion and extraction of elements and encoded objects using a stream buffer of class basic_filebuf<Elem, Tr>, with elements of type Elem, whose character traits are determined by the class Tr.
template <class Elem, class Tr = char_traits<Elem> >
class basic_fstream : public basic_iostream<Elem, Tr>
매개 변수
Elem
The basic element of the file buffer.Tr
The traits of the basic element of the file buffer (usually char_traits<Elem>).
설명
The object stores an object of class basic_filebuf<Elem, Tr>.
참고
The get pointer and put pointer of an fstream object are NOT independent of each other.If the get pointer moves, so does the put pointer.
예제
The following example demonstrates how to create a basic_fstream object that can be read from and written to.
// basic_fstream_class.cpp
// compile with: /EHsc
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
fstream fs("fstream.txt", ios::in | ios::out | ios::trunc);
if (!fs.bad())
{
// Write to the file.
fs << "Writing to a basic_fstream object..." << endl;
fs.close();
// Dump the contents of the file to cout.
fs.open("fstream.txt", ios::in);
cout << fs.rdbuf();
fs.close();
}
}
생성자
'basic_fstream' 형식의 개체를 생성합니다. |
멤버 함수
Closes a file. |
|
Determines if a file is open. |
|
파일을 엽니다. |
|
Returns the address of the stored stream buffer, of type pointer to basic_filebuf<Elem, Tr>. |
|
Exchanges the content of this object with the content of another basic_fstream object. |
요구 사항
Header: <fstream>
네임스페이스: std