C++ iomanip get_time() Function
Example
Read the date "2026-11-05" from a string:
tm date = {};
istringstream input("2026-11-05");
input >> get_time(&date, "%Y-%m-%d");
cout << date.tm_mday << "." << date.tm_mon + 1 << "." << date.tm_year + 1900;
Definition and Usage
The get_time() function reads a date and time in the format you choose, and stores it in a tm structure.
In the example, an istringstream (from the <sstream> library) reads from a string, just like cin reads from the keyboard.
The get_time function is defined in the <iomanip> header file.
Syntax
get_time(tm* time, const char* format)
Parameter Values
| Parameter | Description |
|---|---|
| time | Required. A pointer to the tm structure to store the date and time in. |
| format | Required. A text with format codes that describe the input, like "%Y-%m-%d". |
Technical Details
| Returns: | A manipulator that you use with >>. |
|---|