Translations of this page?:

C++ I/O

<iostream> ライブラリはいくつかの標準オブジェクトを自動的に定義します:

  • cout, ostreamクラスのオブジェクトで、標準出力デバイスにデータを出力します
  • cerr, ostreamクラスのもう一つのオブジェクトで、標準エラーデバイスにバッファされない出力を書き込みます
  • clog, cerrと似ていますが、バッファされた出力を用います
  • cin, istreamクラスのオブジェクトで、標準入力デバイスからデータを読み込みます

<fstream> ライブラリはファイル入力とファイル出力をそれぞれ ifstream クラスと ofstream クラスによって可能にします。 C++では stringstream によっても文字列の入出力が可能になります。

C++ I/O ストリームのいくつかの挙動(精度、行端揃えなど)は様々な I/O ストリームフォーマットフラグ を操作することにより変更できます。

I/O Constructorsconstructors
badtrue if an error occurred
clearclear and set status flags
closeclose a stream
eoftrue if at the end-of-file
exceptionsset the stream to throw exceptions on errors
failtrue if an error occurred
fillmanipulate the default fill character
flagsaccess or manipulate io_stream_format_flags
flushempty the buffer
gcountnumber of characters read during last input
getread characters
getlineread a line of characters
goodtrue if no errors have occurred
ignoreread and discard characters
openopen a new stream
peekcheck the next input character
precisionmanipulate the precision of a stream
putwrite characters
putbackreturn characters to a stream
rdstatereturns the state flags of the stream
readread data into a buffer
seekgperform random access on an input stream
seekpperform random access on output streams
setfset format flags
sync_with_stdiosynchronize with standard I/O
tellgread input stream pointers
tellpread output stream pointers
unsetfclear io_stream_format_flags
widthaccess and manipulate the minimum field width
writewrite characters
 
• • • IndexRecent changesRSScc