:
getline: , , "\n". .
, :
string someStr;
getline(cin, someStr);
" → " ( ): .
, , char.
.
int someInt;
std::cin >> someInt;
, :
string someStr;
cin >> someStr;
, " ", cin , "" - , "( ), I, someStr =" I".
IMP:
→ getline , .
→ , "\n" (newline char) .
, ,
int someStr, someStr2;
std::cin >> someStr;
getline(cin, someStr2);
since → does not recognize the "\ n" char, it will only see "Batman" and exit the buffer, leaving "\ n" for someStr2. So, someStr2 will not get "Bruce", but "" (new char line).
source
share