2014-01-12 99 views
0
cout<<"\nEnter Date of Birth"; 
cin>>date; 
cout<<"-"; 
cin>>month; 
cout<<"-"; 
cin>>year; 

默認「\ n」在此代碼,我想輸入被視爲25-02-1994(破折號自動輸入先前值之後出現)。但,代替「\n」是附加自動和輸入取爲避免與COUT

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

我不得不標記(「\n」)來標記破折號出現在新line.Any建議??

+0

入住這http://stackoverflow.com/questions/15425107/line-spacing-after-endl-and-cout –

+4

爲什麼不輸入整條生產線來代替,並解析它基於短劃線的位置? – 2014-01-12 07:07:25

+1

這是在輸入時在控制檯中按Enter鍵的行爲,而不是'std :: cout'。 – chris

回答

0

因爲你按回車。這是正常的。如果你不想要'\ n'字符,請將其刪除。

date [ strlen(date) - 1] = '\0'; 
month[ strlen(month) - 1] = '\0'; 
year [ strlen(year) - 1] = '\0';