For linux, the below code does what you want (reference this SO thread which you should read Capture characters from standard input without waiting for enter to be pressed ):
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <termios.h>
using namespace std;
char getch(void) {
char buf = 0;
struct termios old = {0};
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
if (read(0, &buf, 1) < 0)
perror ("read()");
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror ("tcsetattr ~ICANON");
return (buf);
}
void readn(char *data, int N) {
for(int ii = 0; ii < N; ii++) { data[ii] = getch(); cout << data[ii]; cout.flush(); };
};
int main () {
char day[2], month[2], year[4];
cout<<"Enter Date Of Birth: "; cout.flush();
readn(day, 2); cout << "/"; cout.flush();
readn(month, 2); cout << "/"; cout.flush();
readn(year, 4); cout << endl; cout.flush();
}