Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2017 23:40
How to define a structure in C++
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct time_of_day
{
int sec;
int min;
int hour;
};
void print_time(time_of_day time)
{
cout << setw(2) << setfill('0') << time.hour << ":";
cout << setw(2) << setfill('0') << time.min << ":";
cout << setw(2) << setfill('0') << time.sec << endl;
}
int main()
{
time_of_day start_work;
start_work.hour = 8;
start_work.min = 30;
start_work.sec = 12;
time_of_day end_work;
end_work.hour = 17;
end_work.min = 0;
end_work.sec = 30;
print_time(start_work);
print_time(end_work);
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment