banner



how to use getline in c++

getline (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

 Live Demo

#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

raja

Published on 30-Dec-2019 09:56:55

  • Related Questions & Answers
  • How to use getline() in C++ when there are blank lines in input?
  • Why does std::getline() skip input after a formatted extraction?
  • Equals(String, String) Method in C#
  • String Literal Vs String Object in C#
  • String class in C#
  • Randomize string in C#
  • String at () in C++
  • Prime String in C++
  • Decode String in C++
  • Reorganize String in C++
  • Magical String in C++
  • Interleaving String in C++
  • Minimum String in C++
  • Compress String in C++
  • Reverse a string in C/C++

how to use getline in c++

Source: https://www.tutorialspoint.com/getline-string-in-cplusplus

Posted by: phiferanducalliew.blogspot.com

0 Response to "how to use getline in c++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel