C++ String Length

C++ String Length


Description: getline is a standard library function. This function is used to read a line or string from a standard input stream like istream. The lines or strings are read until “\n” which is considered as delimitation character is encountered.

As a different version of getline, a third parameter “char delim” can be specified. This is a delimiter character specified explicitly. In this function, a line of text or string will be read until the delimiter character specified is encountered.

Given below is a simple example to demonstrate usage of getline.

Example:

#include <iostream>

#include <string>

using namespace std;

 

int main()

{

    string mystr;

    cout<<"Enter the input string:"<<endl;

    getline(cin,mystr);

    cout<<"You entered: "<<mystr;