
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Line from String in C++
It is used to extracts characters from the stream as unformatted input and stores them into s as a c-string, until either the extracted character is the delimiting character, or n characters have been written to s (including the terminating null character). The declaration is like:
basic_istream& getline (char_type* s, streamsize n ); basic_istream& getline (char_type* s, streamsize n, char_type delim);
The parameters are ‘s’ pointer to an array of characters, where the extracted characters are stored as a c_string. Next parameter is ‘n’ this is the maximum number of characters to write (including the terminating character). The third parameter is ‘delim’ Explicit delimiting character. The operation of extracting successive characters stops as soon as the next character to exact compares equal to this (using traits_type::eq)
This function returns the basic_istream object (*this).
Example
#include <iostream> using namespace std; int main () { char name[256], title[256]; cout << "Please, enter your name: "; cin.getline (name,256); cout << "Please, enter your favourite movie: "; cin.getline (title,256); cout << name << "'s favourite movie is " << title; }
Output
Please, enter your name: Jack Please, enter your favourite movie: The Boss Baby Jack's favourite movie is The Boss Baby