You would have seen this message when you telnet to an unix machine, it displays
last login from <ip address> message
What is the sytem command for displaying the same ? Can I code it in C++ without using system command ?

Hey,

There is a lastlog command in unix that displays the contents of the /var/log/lastlog file, This is a binary file and a structure describing the contents is located in the <bits/utmp.h> header file

struct lastlog
{
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
int32_t ll_time;
#else
__time_t ll_time;
#endif
char ll_line[UT_LINESIZE];
char ll_host[UT_HOSTSIZE];
};

anyhow more useful is prolly this example of a lastlog editor written in C that can be found here