Home >Backend Development >C++ >Usage of cin.getline function in c++
The cin.getline() function reads a line of characters from standard input until the newline character or the specified maximum number of characters. Specific usage: char str[100];cin.getline(str, 100);
##cin.getline() function usage
Introduction:
The cin.getline() function is a function in C used to read a line of characters from standard input. This function reads characters from the stream until a newline character ('\n') is encountered or the specified maximum number of characters is reached.Syntax:
<code class="cpp">istream& cin.getline(char *str, int num);</code>
Parameters:
Return value:
Returns the istream object representing the stream status. If the row is read successfully, the object represents normal status; otherwise, it represents an error status.Usage:
Usually use the cin.getline() function to read user input from the keyboard. The specific usage is as follows:<code class="cpp">char str[100]; cin.getline(str, 100); // 从标准输入读取一行并存储在 str 中</code>
Note:
The above is the detailed content of Usage of cin.getline function in c++. For more information, please follow other related articles on the PHP Chinese website!