getline() Function and Character Array in C++ Last Updated : 17 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The C++ getline() is a standard library function that is used to read a string or a line from an input stream. It is a part of the <string> header. The getline() function extracts characters from the input stream and appends it to the string object until the delimiting character is encountered. Must read the article getline(string) in C++ for more details. In C++, stream classes support line-oriented functions, getline() and write() to perform input and output functions respectively. Getline Character Array: This function reads the whole line of text that ends with a new line or until the maximum limit is reached. getline() is the member function of istream class. Syntax: // (buffer, stream_size, delimiter) istream& getline(char*, int size, char='\n') // The delimiter character is considered as '\n' istream& getline(char*, int size) Parameters: char*: Character pointer that points to the array.Size: Acts as a delimiter that defines the size of the array. The Function Does the Following Operations: Extracts character up to the delimiter. Stores the characters in the buffer. The maximum number of characters extracted is size - 1. Note: that the terminator(or delimiter) character can be any character (like ' ', ', ' or any special character, etc.). The terminator character is read but not saved into a buffer, instead it is replaced by the null character. For Example: Input: Aditya Rakhecha CPP // C++ program to show the getline() with // character array #include <iostream> using namespace std; // Driver Code int main() { char str[20]; cout << "Enter Your Name::"; // see the use of getline() with array // str also replace the above statement // by cin >> str and see the difference // in output cin.getline(str, 20); cout << "\nYour Name is:: " << str; return 0; } Output Your Name is:: Aditya Rakhecha Explanation: In the above program, the statement cin.getline(str, 20); reads a string until it encounters the new line character or the maximum number of characters (here 20). Try the function with different limits and see the output. Comment More infoAdvertise with us Next Article iscntrl() in C++ and its application to find control characters A AdityaRakhecha Follow Improve Article Tags : Misc C/C++ Puzzles C++ cpp-string Practice Tags : CPPMisc Similar Reads array get() function in C++ STL The array::get() is a built-in function in C++ STL which returns a reference to the i-th element of the array container. Syntax: get(array_name) Parameters: The function accepts two mandatory parameters which are described below. i - position of an element in the array, with 0 as the position of the 2 min read Function Pointers and Callbacks in C++ A callback is a function that is passed as an argument to another function. In C++, we cannot directly use the function name to pass them as a callback. We use function pointers to pass callbacks to other functions, store them in data structures, and invoke them later. In this article, we will discu 2 min read Wide char and library functions in C++ Wide char is similar to char data type, except that wide char take up twice the space and can take on much larger values as a result. char can take 256 values which corresponds to entries in the ASCII table. On the other hand, wide char can take on 65536 values which corresponds to UNICODE values wh 7 min read iscntrl() in C++ and its application to find control characters In C++, iscntrl() is a predefined function used for string and character handling. cstring is the header file required for string functions and cctype is the header file required for character functions. A control character is one which is not a printable character i.e, it does not occupy a printing 3 min read Character Classification in C++ : cctype Character classification in C++ is possible using functions specified in function library. These functions are included in the <cctype> header file. Numerous functions to classify characters are discussed below:1. isalpha(): This function returns true if the character is an alphabet else retur 7 min read Arrays and Strings in C++ Arrays An array in C or C++ is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar types of elements as in the data type must be the same for all elements. They can be used to store the collection 5 min read Like