Input/Output Streams Terminology Reference

This reference provides an overview of I/O streams terminology you'll encounter in this chapter. Use it as a quick lookup guide.

Stream Basics

Term Definition Example
Stream Abstraction for sequential I/O operations std::cin, std::cout, file streams
Input Stream Stream for reading data std::istream, std::ifstream
Output Stream Stream for writing data std::ostream, std::ofstream
I/O Stream Bidirectional stream for reading and writing std::iostream, std::fstream
Stream Buffer Internal buffer managing actual I/O std::streambuf
Standard Streams Predefined streams for console I/O std::cin, std::cout, std::cerr, std::clog

File Streams

Term Definition Example
ifstream Input file stream for reading files std::ifstream file{"data.txt"};
ofstream Output file stream for writing files std::ofstream file{"output.txt"};
fstream File stream for reading and writing std::fstream file{"data.txt", std::ios::in | std::ios::out};
File Mode Flags controlling file opening behavior std::ios::in, std::ios::out, std::ios::app
Binary Mode Reading/writing raw bytes std::ios::binary
Text Mode Default mode with text processing Newline conversion on Windows

File Open Modes

Term Definition Example
std::ios::in Open for reading std::ifstream file{"data.txt", std::ios::in};
std::ios::out Open for writing, truncate if exists std::ofstream file{"data.txt", std::ios::out};
std::ios::app Append to end of file std::ofstream file{"log.txt", std::ios::app};
std::ios::ate Seek to end after opening std::fstream file{"data.txt", std::ios::ate};
std::ios::trunc Truncate file if it exists std::ofstream file{"data.txt", std::ios::trunc};
std::ios::binary Binary mode, no text processing std::ifstream file{"image.png", std::ios::binary};

Stream States

Term Definition Example
goodbit Stream is ready for I/O file.good() returns true
eofbit End of file reached file.eof() returns true
failbit Logical error occurred file.fail() returns true
badbit Fatal error occurred file.bad() returns true
Stream State Current condition of stream Combination of state bits
clear() Resets stream state file.clear();
setstate() Sets specific state bits file.setstate(std::ios::failbit);

Stream Operations

Term Definition Example
Extraction Operator Reads formatted input from stream file >> value;
Insertion Operator Writes formatted output to stream file << value;
get() Reads single character char ch{file.get()};
put() Writes single character file.put('A');
getline() Reads entire line std::getline(file, line);
read() Reads raw bytes file.read(buffer, size);
write() Writes raw bytes file.write(data, size);
peek() Looks at next character without extracting char next{file.peek()};
ignore() Skips characters in stream file.ignore(100, '\n');

Stream Positioning

Term Definition Example
tellg() Returns current input position std::streampos pos{file.tellg()};
tellp() Returns current output position std::streampos pos{file.tellp()};
seekg() Sets input position file.seekg(0, std::ios::beg);
seekp() Sets output position file.seekp(0, std::ios::end);
std::ios::beg Beginning of stream Used with seek functions
std::ios::cur Current position in stream Used with seek functions
std::ios::end End of stream Used with seek functions

Stream Formatting

Term Definition Example
Manipulator Function modifying stream behavior std::endl, std::setw, std::hex
std::endl Inserts newline and flushes buffer std::cout << "Hello" << std::endl;
std::flush Flushes output buffer std::cout << "Data" << std::flush;
std::setw Sets field width for next output std::cout << std::setw(10) << value;
std::setprecision Sets floating-point precision std::cout << std::setprecision(2) << 3.14159;
std::fixed Fixed-point notation std::cout << std::fixed << 3.14;
std::scientific Scientific notation std::cout << std::scientific << 1000.0;
std::hex Hexadecimal output std::cout << std::hex << 255;
std::dec Decimal output (default) std::cout << std::dec << 255;
std::oct Octal output std::cout << std::oct << 8;

String Streams

Term Definition Example
istringstream Input string stream for parsing std::istringstream iss{"42 3.14"};
ostringstream Output string stream for formatting std::ostringstream oss; oss << 42;
stringstream Bidirectional string stream std::stringstream ss;
str() Gets or sets string content std::string s{ss.str()};
String-based I/O Using strings as I/O source/destination Parsing, formatting in memory

Buffer Management

Term Definition Example
Buffering Temporary storage before actual I/O Improves performance
Flush Writing buffer contents to destination std::cout.flush();
Buffer Size Size of internal buffer Usually system-dependent
Unbuffered I/O Direct I/O without buffering std::cerr is unbuffered
Line Buffered Flushes on newline std::cout is line buffered
Full Buffered Flushes when full File streams typically
rdbuf() Access or replace stream buffer std::cout.rdbuf(file.rdbuf());

Advanced Stream Concepts

Term Definition Example
Stream Iterator Iterator wrapping stream operations std::istream_iterator<int>
Stream Buffer Iterator Low-level iterator for stream buffer std::istreambuf_iterator<char>
Custom Manipulator User-defined stream manipulator Function returning stream reference
Stream Tie Linking output stream to input stream std::cin.tie(&std::cout);
Stream Locale Locale for formatting/parsing file.imbue(std::locale{});
Stream Callback Function called on stream events file.register_callback()

Error Handling

Term Definition Example
Stream Exception Throwing exceptions on stream errors file.exceptions(std::ios::failbit);
Exception Mask Which errors trigger exceptions Set with exceptions()
Error Checking Testing stream state after operation if (!file) { } or if (file.fail()) { }
Stream Boolean Conversion Implicit conversion to bool if (file >> value) checks success
Fail State Stream failed but recoverable Can clear and retry
Bad State Irrecoverable stream error Stream unusable

Binary I/O

Term Definition Example
Binary Read Reading raw bytes from file file.read(reinterpret_cast<char*>(&data), sizeof(data));
Binary Write Writing raw bytes to file file.write(reinterpret_cast<const char*>(&data), sizeof(data));
gcount() Returns number of characters read by last operation std::streamsize count{file.gcount()};
Serialization Converting object to byte stream Writing object state to file
Deserialization Reconstructing object from byte stream Reading object state from file