100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Unformatted I/O Functions in C++

Learn C++ unformatted input/output functions like `cin.get()`, `cin.put()`, and `cin.ignore()` for low-level, character-based stream handling.

Input & OutputIntermediate6 min readJul 7, 2026
Analogies

1. Intro

Unformatted I/O functions operate on raw characters or blocks of data without applying any formatting rules, unlike >> and << which skip whitespace and interpret types. They give finer, low-level control over exactly what is read from or written to a stream, one character (or a specific delimiter) at a time.

🏏

Cricket analogy: While a normal scoreboard summary skips extraneous details and reports only clean totals (like >>/<<), a ball-by-ball raw commentary log records every single delivery including wides and dead balls without filtering - that's unformatted I/O.

2. Syntax

cpp
char c = cin.get();      // read one character
cin.get(c);               // read one character into c
cout.put(c);               // write one character
cin.ignore(n, delim);     // skip n characters or until delim

3. Explanation

cin.get() reads a single character from the input stream, including whitespace characters that cin >> would normally skip, making it useful for character-by-character processing. cout.put() writes a single character to the output stream. cin.ignore(n, delim) discards up to n characters from the input buffer, or stops early if the delimiter character is found — commonly used to clear a leftover newline before a getline() call. These functions are considered unformatted because they do not perform any type conversion or whitespace skipping.

🏏

Cricket analogy: cin.get() reading one character including whitespace is like an umpire signaling every single delivery outcome individually, even the dot balls that a summary would normally skip; cin.ignore() is like discarding a rain delay before resuming play.

cin.get() does NOT skip leading whitespace like cin >> does, so calling it right after cin >> var; will often read the leftover newline character instead of the next meaningful character.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    char ch;
    cout << "Enter a character: ";
    cin.get(ch);

    cout << "You entered: ";
    cout.put(ch);
    cout << endl;

    cin.ignore(100, '\n'); // clear rest of the line
    return 0;
}

5. Output

text
Enter a character: Z
You entered: Z

6. Key Takeaways

  • cin.get() reads a single character, including whitespace, unlike cin >>.
  • cout.put() writes a single character to the output stream.
  • cin.ignore(n, delim) discards characters, commonly used to clear a leftover newline.
  • Unformatted I/O functions do not skip whitespace or perform type conversion, unlike >> and <<.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#UnformattedIOFunctionsInC#Unformatted#Functions#Syntax#Explanation#StudyNotes#SkillVeris#ExamPrep