visual c++ Keyboard Input | getline function

preview_player
Показать описание
As you have already seen, the cin operator allows you to input data from the keyboard. However, it is not the only method or necessarily the best for all situations (but it is the simplest). The two other most commonly used methods are get and getline. The get function will retrieve a single character, no matter how much the user types in. The getline function will retrieve a certain number of characters, a number that you specify. This is particularly important when putting the data into an array.

You should notice that only 10 characters are placed in the character array, no matter how many you enter. In fact, you should probably prove this to yourself by deliberately typing in more text. This means that getline is the safe choice if you want to enter a string of characters into an array.
Рекомендации по теме