0
cout<<"\nEnter Date of Birth";
cin>>date;
cout<<"-";
cin>>month;
cout<<"-";
cin>>year;

In this code, I want the input to be taken as 25-02-1994(the dashes appear automatically after the preceding value is entered).But,instead a '\n' is appended automatically and the input is taken as

Enter Date of Birth25
('\n')-02
('\n')-1994

I had to mark ('\n') to mark that the dashes appear on a new line.Any suggestions??

Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
  • Check this http://stackoverflow.com/questions/15425107/line-spacing-after-endl-and-cout – Suvarna Pattayil Jan 12 '14 at 07:05
  • 4
    Why not input an entire line instead, and parse it based on the location of the dashes? –  Jan 12 '14 at 07:07
  • 1
    That's the behaviour of pressing enter in your console while inputting, not `std::cout`. – chris Jan 12 '14 at 07:14
  • It sounds like you're looking for low-level keystroke console interaction, and if so, there is no standard language or library support for such requirements. There are per-platform solutions, but thats about as good as you're going to get. This assuming it appears you want `'-'` to emit as soon as the user enters two digits, then again after two more, etc. – WhozCraig Jan 12 '14 at 07:58

1 Answers1

0

Because you hit enter. It's normal. If you don't want the '\n' character, remove it.

date [ strlen( date ) - 1] = '\0';
month[ strlen( month) - 1] = '\0';
year [ strlen( year ) - 1] = '\0';
Mustafa Chelik
  • 2,113
  • 2
  • 17
  • 29