#include <fstream>
파일에 출력하기 - ofstream
ofstream 변수선언;
ex)
ofstream val("filename");
---------- or ----------
ofstream val;
val.open("filename")
val << "Hello world"; //<-해당 파일에 "Hello world"가 기록된다.
파일에 입력하기 - ifstream
ifstream 변수선언;
ex)
ifstream val("filename");
---------- or ----------
ifstream val;
val.open("filename")
val >> buf; //<-해당 파일에서 한 단어를 buf에 입력한다.
파일 사용후 .close()해준다.
Public members
- (constructor)
- Construct object and optionally open file (constructor member)
- rdbuf
- Get the associated filebuf object (public member function )
- is_open
- Check if a file is open (public member function)
- open
- Open file (public member function )
- close
- Close file (public member function)
Members inherited from istream
- operator>>
- Extract formatted data (public member function )
- gcount
- Get number of characters extracted by last unformatted input operation (public member function)
- get
- Get unformatted data from stream (public member function )
- getline
- Get line from stream (public member function )
- ignore
- Extract and discard characters (public member functions)
- peek
- Peek next character (public member function )
- read
- Read block of data (public member function)
- readsome
- Read block of data available in the buffer (public member function )
- putback
- Put character back (public member function )
- unget
- Decrement get pointer (public member function )
- tellg
- Get position of the get pointer. (public member function )
- seekg
- Set position of the get pointer (public member function )
- sync
- Synchronize input buffer with source of characters (public member function)
- sentry
- Perform exception safe prefix/suffix operations (public member class)
Members inherited from ostream
- operator<<
- Insert data with format (public member function )
- put
- Put character (public member function)
- write
- Write block of data (public member function )
- tellp
- Get position of put pointer (public member function)
- seekp
- Set position of put pointer (public member function )
- flush
- Flush output stream buffer (public member function)
- sentry
- Perform exception safe prefix/suffix operations (public member classes)
Member functions inherited from ios
- good
- Check if the state of the stream is good for i/o operations. (public member function)
- eof
- Check if eofbit is set (public member function)
- fail
- Check if either failbit or badbit is set (public member function )
- bad
- Check if badbit is set (public member function)
- operator!
- Evaluate stream object (public member function)
- operator void*
- Convert to pointer (public member function)
- rdstate
- Get error state flags (public member function)
- setstate
- Set error state flag (public member function)
- clear
- Set error state flags (public member function)
- copyfmt
- Copy formatting information (public member functions)
- fill
- Get/set the fill character (public member function)
- exceptions
- Get/set exception mask (public member function)
- imbue
- Imbue locale (public member function)
- tie
- Get/set the tied stream (public member function)
- narrow
- Narrow character (public member function)
- widen
- Widen character (public member function)
Member functions inherited from ios_base
- flags
- Get/set format flags (public member function)
- setf
- Set specific format flags (public member function)
- unsetf
- Clear specific format flags (public member function)
- precision
- Get/Set floating-point decimal precision (public member function )
- width
- Get/set field width (public member function)
- imbue
- Imbue locale (public member function)
- getloc
- Get current locale (public member function)
- xalloc
- Return a new index for the internal extensible array [static] (public static member function)
- iword
- Get reference to integer element of the internal extensible array (public member function)
- pword
- Get reference to pointer of the internal extensible array (public member function)
- register_callback
- Register event callback function (public member function)
- sync_with_stdio
- Activate/deactivate synchronization of iostream and cstdio streams [static] (public static member function)
Reference : http://www.cplusplus.com/reference/iostream/fstream/
'Programming > C/C++' 카테고리의 다른 글
프로그램 종료2 - atexit(), _exit() (0) | 2012.05.03 |
---|---|
프로그램 종료 - assert(), exit(), abort() (0) | 2012.05.02 |
PF_INET와 AF_INET (3) | 2012.04.30 |
헤더파일 중복 방지( inclusion guard / #pragma once ) (0) | 2012.04.23 |
cin.fail cin.clear cin.ignore (3) | 2012.04.20 |