the use of getline

1. Enter string

 

String s1; 
getline (cin, s1); 
cin >> s1; // Note cin encounter spaces will be terminated and will not getline

 

2. Enter question about swallow

After entering n remember to swallow ENTER, or can only enter two string ends

 

>> CIN n-; 
getchar (); // add getchar () when the carriage eaten input n- 
getline (CIN, S1); 
getline (CIN, S2); 
getline (CIN, S3);

 

Guess you like

Origin www.cnblogs.com/1911087165zzx/p/11343709.html