The document provides a comprehensive list of 10 basic input and output functions and manipulators in C++, including their uses, definitions, and example outputs. It details common stream objects like cin and cout for input and output, manipulators for controlling formatting of data types, and functions for reading and writing data to streams. Examples are given to demonstrate how each function or manipulator is called and used.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
28 views2 pages
Basics
The document provides a comprehensive list of 10 basic input and output functions and manipulators in C++, including their uses, definitions, and example outputs. It details common stream objects like cin and cout for input and output, manipulators for controlling formatting of data types, and functions for reading and writing data to streams. Examples are given to demonstrate how each function or manipulator is called and used.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Certainly, here's a comprehensive list of basic input and output functions, manipulators, their
uses, definitions, and example outputs:
1. Input Stream (cin):
Use: Reads data from the user or input source. Definition: The standard input stream object. Example: cppCopy code int num; cout << "Enter a number: " ; cin >> num; 2. Output Stream (cout, cerr, clog): Use: Writes data to the console or output destination. Definition: The standard output stream object (cout), standard error stream (cerr) for error messages, and standard logging stream (clog) for log messages. Example: cppCopy code cout << "Hello, world!" << endl; cerr << "Error: Something went wrong." << endl; clog << "Logging: This is an informational message." << endl; 3. endl and flush: Use: Manipulators for controlling line breaks and flushing the output buffer. Definition: endl inserts a newline and flushes the buffer, flush only flushes the buffer. Example: cppCopy code cout << "Hello, world!" << endl; cout << "This is another line." << flush; 4. Boolean Formatting (boolalpha, noboolalpha): Use: Manipulators for controlling boolean output formatting. Definition: boolalpha shows boolean values as "true" or "false", noboolalpha shows them as 1 or 0. Example: cppCopy code bool value = true ; cout << "Value (boolalpha): " << boolalpha << value << endl; cout << "Value (noboolalpha): " << noboolalpha << value << endl;
Use: Manipulators for controlling integer output formatting. Definition: hex, dec, oct set the base (hexadecimal, decimal, octal), showbase adds base prefix, noshowbase removes base prefix. Example: cppCopy code int value = 42 ; cout << "Hexadecimal: " << hex << value << endl; cout << "Decimal: " << dec << value << endl; cout << "Octal: " << oct << value << endl; cout << "Hexadecimal (with base): " << showbase << hex << value << endl; cout << "Hexadecimal (without base): " << noshowbase << hex << value << endl; 6. Floating-Point Formatting (scientific, fixed, defaultfloat): Use: Manipulators for controlling floating-point output formatting. Definition: scientific shows in scientific notation, fixed shows in fixed-point notation, defaultfloat reverts to default notation. Example: cppCopy code double value = 123456.789 ; cout << "Scientific notation: " << scientific << value << endl; cout << "Fixed-point notation: " << fixed << value << endl; cout << "Default notation: " << defaultfloat << value << endl; 7. Whitespace Manipulation (ws): Use: Manipulator for extracting whitespace characters from the input stream. Definition: ws extracts whitespace characters from the input stream. Example: cppCopy code string name; cin >> ws; // Extract any leading whitespace getline (cin, name); // Read the entire line, including spaces 8. Stream Manipulators (setw, setprecision): Use: Manipulators for controlling output field width and floating-point precision. Definition: setw sets the width of the output field, setprecision sets the number of decimal places. Example: cppCopy code #include <iomanip> using namespace std; double pi = 3.14159265359 ; cout << "Value of pi: " << setprecision ( 4 ) << pi << endl; cout << "Formatted width: " << setw ( 10 ) << "Hello" << endl; 9. Stream Extraction (getline): Use: Reads an entire line from the input stream. Definition: A function that reads characters from the input stream until a newline character is encountered. Example: cppCopy code string input; getline (cin, input); 10. Stream Insertion (<<, >>): Use: Inserts data into the output stream or extracts data from the input stream. Definition: Operators used for writing to the output stream (<<) or reading from the input stream (>>). Example: cppCopy code int num = 42 ; cout << "Number: " << num << endl; cin >> num;
These are the basic functions, manipulators, their uses, definitions, and example outputs provided by the <iostream> header in C++ for input and output operations.