C++ Program To Read String Using tline()
Maybe your like
- Home
- DS & Algo. ▾
- Data Structure Tutorial
- Algorithms Tutorial
- Coding Problems
- Languages ▾
- C Tutorial
- C++ Tutorial
- C++ STL Tutorial
- Java Tutorial
- Python Tutorial
- Scala Tutorial
- Ruby Tutorial
- C#.Net Tutorial
- Golang Tutorial
- Android Tutorial
- Kotlin Tutorial
- SQL Tutorial
- Web. ▾
- JavaScript Tutorial
- CSS Tutorial
- jQuery Tutorial
- PHP Tutorial
- Node.Js Tutorial
- AdonisJs Tutorial
- VueJS Tutorial
- Ajax Tutorial
- HTML Tutorial
- Django Tutorial
- Programs ▾
- C Programs
- C++ Programs
- Data Structure Programs
- Java Programs
- C#.Net Programs
- VB.Net Programs
- Python Programs
- PHP Programs
- Golang Programs
- Scala Programs
- Swift Programs
- Rust Programs
- Ruby Programs
- Kotlin Programs
- C Interview Programs
- Aptitude ▾
- C Aptitude
- C++ Aptitude
- Java Aptitude
- C# Aptitude
- PHP Aptitude
- Linux Aptitude
- DBMS Aptitude
- Networking Aptitude
- AI Aptitude
- English Grammar Aptitude
- More...
- Interview ▾
- Golang Interview Questions
- MIS Executive Interview Questions
- DBMS Interview Questions
- C Interview Questions
- Embedded C Interview Questions
- Java Interview Questions
- SEO Interview Questions
- HR Interview Questions
- Find Output ▾
- C Find O/P
- C++ Find O/P
- C#.Net Find O/P
- Java Find O/P
- Go Find O/P
- PHP Find O/P
- More...
- MCQs ▾
- Web Technologie MCQs
- CS Subjects MCQs
- Databases MCQs
- Programming MCQs
- Testing Software MCQs
- Digital Mktg Subjects MCQs
- Cloud Computing S/W MCQs
- Engineering Subjects MCQs
- Commerce MCQs
- More MCQs...
- CS Subjects ▾
- ML/AI Tutorial
- Operating System Tutorial
- Computer Network Tutorial
- Software Engineering Tutorial
- Discrete Mathematics Tutorial
- Digital Electronics Tutorial
- Data Mining Tutorial
- MIS Tutorial
- DBMS Tutorial
- Embedded Systems Tutorial
- Cryptography Tutorial
- CS Fundamental Tutorial
- More Tutorials...
- More ▾
- Tech Articles
- Puzzles
- Full Forms
- Code Examples
- Blogs
- Guest Post
- Programmer's Calculator
- XML Sitemap Generator
- Tools & Generators
- About
- Contact
- Home
- DS & Algo. ▾
- Data Structure Tutorial
- Algorithms Tutorial
- Coding Problems
- Languages ▾
- C Tutorial
- C++ Tutorial
- C++ STL Tutorial
- Java Tutorial
- Python Tutorial
- Scala Tutorial
- Ruby Tutorial
- C#.Net Tutorial
- Golang Tutorial
- Android Tutorial
- Kotlin Tutorial
- SQL Tutorial
- Web. ▾
- JavaScript Tutorial
- CSS Tutorial
- jQuery Tutorial
- PHP Tutorial
- Node.Js Tutorial
- AdonisJs Tutorial
- VueJS Tutorial
- Ajax Tutorial
- HTML Tutorial
- Django Tutorial
- Programs ▾
- C Programs
- C++ Programs
- Data Structure Programs
- Java Programs
- C#.Net Programs
- VB.Net Programs
- Python Programs
- PHP Programs
- Golang Programs
- Scala Programs
- Swift Programs
- Rust Programs
- Ruby Programs
- Kotlin Programs
- C Interview Programs
- Aptitude ▾
- C Aptitude
- C++ Aptitude
- Java Aptitude
- C# Aptitude
- PHP Aptitude
- Linux Aptitude
- DBMS Aptitude
- Networking Aptitude
- AI Aptitude
- English Grammar Aptitude
- More...
- Interview ▾
- Golang Interview Questions
- MIS Executive Interview Questions
- DBMS Interview Questions
- C Interview Questions
- Embedded C Interview Questions
- Java Interview Questions
- SEO Interview Questions
- HR Interview Questions
- Find Output ▾
- C Find O/P
- C++ Find O/P
- C#.Net Find O/P
- Java Find O/P
- Go Find O/P
- PHP Find O/P
- More...
- MCQs ▾
- Web Technologie MCQs
- CS Subjects MCQs
- Databases MCQs
- Programming MCQs
- Testing Software MCQs
- Digital Mktg Subjects MCQs
- Cloud Computing S/W MCQs
- Engineering Subjects MCQs
- Commerce MCQs
- More MCQs...
- CS Subjects ▾
- ML/AI Tutorial
- Operating System Tutorial
- Computer Network Tutorial
- Software Engineering Tutorial
- Discrete Mathematics Tutorial
- Digital Electronics Tutorial
- Data Mining Tutorial
- MIS Tutorial
- DBMS Tutorial
- Embedded Systems Tutorial
- Cryptography Tutorial
- CS Fundamental Tutorial
- More Tutorials...
- More ▾
- Tech Articles
- Puzzles
- Full Forms
- Code Examples
- Blogs
- Guest Post
- Programmer's Calculator
- XML Sitemap Generator
- Tools & Generators
- About
- Contact
C++ Programs
- C++ Programs - Home
- C++ Most popular & Searched Programs
- C++ Basic Input/Output Programs
- C++ Constructor & Destructor Programs
- C++ Manipulators Programs
- C++ Inheritance Programs
- C++ Operator Overloading Programs
- C++ File Handling Programs
- C++ Bit Manipulation Programs
- C++ Classes & Object programs (Set 1)
- C++ Classes & Object programs (Set 2)
C++ Most popular & Searched Programs
- C++ - Print right angled pyramid of numbers
- C++ - Print right angled pyramid of numbers
- C++ - Keep calculate sum of digits of a number
- C++ - Skip some of array elements
- C++ - Declaring & printing different constants
- C++ - Example of delay() function
- C++ - Print your name randomly
- C++ - Print maximum possible time using six of nine given single digits
- C++ - Find last index of a character in a string
- C++ - Get week day from given date
- C++ - Set date & time
- C++ - Reading date & time
- C++ - Get previous date of given date
- C++ - Find total number of days in given month of year
- C++ - Set network settings for IPv6 Network
- C++ - Pad octets of IP Address with Zeros
- C++ - Set MAC address in Linux Devices
- C++ - Get MAC address of Linux based network device
- C++ - Set IP address, subnet mask, network gateway
- C++ - Check given string is numeric or not
- C++ - Check given date is in valid format or not
- C++ - Add seconds to the time
- C++ - Find Fibonacci number
- C++ - Find next greatest number from the same set of digits
- C++ - Convert number to word
- C++ - Check whether a string2 can be formed from string1
- C++ - Print a spiral matrix
- C++ - Find the frequency of a character in a string
- C++ - Find factorial of large numbers using array
- C++ - Generate random alphabets
- C++ - Print pattern of stars till N number of rows
- C++ - Print a chessboard pattern
- C++ - Print a Pascal Triangle
- C++ - Reverse a number
- C++ - Sort an array in Descending Order
- C++ - Sort an array in Ascending Order
- C++ - Convert lowercase to uppercase & vice versa
- C++ - Check leap year
- C++ - Check if a number is even using Recursion
- C++ - Find odd or even number without using modulus operator
- C++ - Check EVEN or ODD
- C++ - Add two times
- C++ - Display prime numbers
- C++ - Check prime number
- C++ - Find factorial of a number
- C++ - Display name & age
- C++ - Read a string
- C++ - Add two integer numbers using class
- C++ - Add two integer numbers using pointers
- C++ - Add two integer numbers using function
- C++ - Add two integer numbers
C++ Basic I/O Programs
- C++ - Print "Hello World"
- C++ - Read character array
- C++ - Cascading cout & cin
- C++ - Use of Resolution Operator(SRO)
- C++ - Use of reference variable
- C++ - Use function as a LVALUE using reference variable
- C++ - Inline Function Example
- C++ - Default Argument Example
- C++ - Methods of passing in function
- C++ - Function overloading example
- C++ - Read string using cin.getline()
- C++ - Generate random numbers
- C++ - Print Reverse Triangle Bridge Pattern
C++ Constructor & Destructor Programs
- C++ - Example of default constructor or no argument constructor
- C++ - Example of parameterized constructor
- C++ - Example of copy constructor
- C++ - Example of constructor overloading
- C++ - Example of member initializer list
- C++ - Example of destructors
- C++ - Example of constructor using this pointer
- C++ - Example of constructor with default arguments
- C++ - Dynamic Initialization of Objects
- C++ - Set values of data members
- C++ - Create a class with inline functions
- C++ - Create a constructor with default arguments
- C++ - Create a class with two constructors
C++ Manipulators Programs
- C++ - Example of endl manipulator
- C++ - Example of setw manipulator
- C++ - Example of setfill manipulator
- C++ - Example of setprecision manipulator
- C++ - Example of setbase manipulator
C++ Inheritance Programs
- C++ - Example of simple inheritance
- C++ - Example of private simple inheritance
- C++ - Read & print student's information using two classes and simple inheritance
- C++ - Example of multilevel inheritance
- C++ - Read ≈ print employee information using multiple inheritance
- C++ - Example of multiple inheritance
- C++ - Get square and cube of a number
- C++ - Read & print employee information with department and pf information using hierarchical inheritance
C++ Operator Overloading Programs
- C++ - Unary minus (-) operator overloading
- C++ - Unary increment (++) and decrement (--) operator overloading
- C++ - Unary logical NOT operator overloading
- C++ - Add two objects using binary plus (+) operator overloading
- C++ - Add two distances using binary plus (+) operator overloading
C++ File Handling Programs
- C++ - Create a file
- C++ - Read a text file
- C++ - Write & read text in/from file
- C++ - Write & read values using variables in/from file
- C++ - Write & read object using read() & write() functions
- C++ - Eample of tellg() & tellp() function
- C++ - Example of tellg(), seekg(), & seekp() Functions
- C++ - Read integers from a text file with ifstream
- C++ - Read data from a text file
- C++ - Append text to a text file
C++ Bit Manipulation Programs
- C++ - Print all possible subset of a set
- C++ - Change case of a character using bit manipulation
- C++ - Find total Number of bits required to represent a number in binary
- C++ - Find next & previous power of two of a given number
C++ Classes & Object Programs
- C++ - Create a simple class & object
- C++ - Create an object of a class & access class attributes
- C++ - Create multiple objects of a class
- C++ - Create class methods
- C++ - Define a class method
- C++ - Assign values to private data members w/o using constructor
- C++ -Create an empty class
- C++ - Create a class with setter & getter methods
- C++ - Create a class to read & add two distance
- C++ - Create a class for student
- C++ - Create a class for student to get & print details of N students
- C++ - Create class to read & add two times
- C++ - Create class convert time in HH:MM:SS format
- C++ - Create class convert time seconds
- C++ - Example of friend function with class
- C++ - Count created objects
- C++ - Find factorial of a number
- C++ - Check the year is leap year or not
- C++ - Add N natural numbers
- C++ - Find largest number b/w three numbers
- C++ - Check if character is vowel or consonant
- C++ - Check if number is odd or even
- C++ - Find power of a number
- C++ - Check if number is palindrome
- C++ - Find reverse of a number
- C++ - Change string from uppercase to lowercase
- C++ - Check number is Armstrong number or not
- C++ - Find largest number of an array
- C++ - Count vowels, consonant, digits & special characters
- C++ - Find length of a string
- C++ - Find addition of two matrices
- C++ - Find multiplication of two matrices
- C++ - Find transpose of a matrix
- C++ - Find all roots of a quadratic equation
- C++ - Convert binary number to octal number
- C++ - Convert octal number to binary number
- C++ - Convert decimal number to octal number
- C++ - Convert octal number to decimal number
- C++ - reverse the string
- C++ - Change string from lowercase to uppercase using class
- C++ - Change string to sentence case
- C++ - Find smallest number in the array
- C++ - Sort an array in ascending order
- C++ - Sort an array in descending order
- C++ - Convert the temperature from Celsius to Fahrenheit
- C++ - Convert the temperature from Fahrenheit to Celsius
- C++ - Print prime numbers in a range
- C++ - Print odd numbers in a range
- C++ - Print even numbers in a range
- C++ - Print Armstrong numbers in a range
- C++ - Print palindrome numbers in a range
- C++ - Find sum of all elements of the array
- C++ - Find product of all elements of the array
- C++ - Find product of all digits of a number
- C++ - Find sum of all digits of a number
- C++ - Check if the number is perfect or not
- C++ - Print the perfect numbers in the given range
- C++ - Convert octal number to hexadecimal
- C++ - Convert hexadecimal to octal number
- C++ - Convert hexadecimal to decimal number
- C++ - Convert decimal number to hexadecimal
- C++ - Find second largest number in the array
- C++ - Find second smallest number in the array
- C++ - Change string to toggle case
- C++ - Change string to title case
- C++ - count total words in the string
- C++ - Convert characters of a string to opposite case using class
- C++ - Find mean of the array
- C++ - Find median of the array
- C++ - Find mode of the array
- C++ - Find sum of digits of numbers between numbers
- C++ - Calculate the minutes between two time periods
- C++ - Check if the numbers in the array are in arithmetic progression
- C++ - Convert the minutes to time
- C++ - Replace a word by another given word in the string
- C++ - Print the leap years in the given time period
- C++ - Find sum of all integers in a string
- C++ - Find sum of prime numbers in a range
- C++ - Find product of prime numbers in a range
- C++ - Find product of digits of numbers between a given range
- C++ - Find product of all integers in a string
- C++ - Check if the numbers in the array are in geometric progression
- C++ - Find difference between the largest & smallest numbers in the array
- C++ - Find area of shapes
- C++ - Find perimeter of shapes
- C++ - Swap first & last digits of a number
- C++ - Add two binary numbers
- C++ - Find area of polygon of several sides
- C++ - Find area of hexagon
- C++ - Calculate the simple interest
- C++ - Calculate the compound interest
- C++ - Find third angle of triangle
- C++ - Convert speed from km/h to miles/h
- C++ - Convert speed from miles/h to km/h
- C++ - Print the sum of all odd & even numbers in a range
- C++ - Print the product of all odd & even numbers in a range
- C++ - Find volume of shapes
- C++ - Find surface area of shapes
- C++ - Reverse name & surname
- C++ - Convert temperature from Celsius to Kelvin
- C++ - Convert temperature from Kelvin to Celsius
- C++ - Convert temperature from Fahrenheit to Kelvin
- C++ - Convert temperature from Kelvin to Fahrenheit
- C++ - Find area of a triangle by heron's formula
- C++ - Find product of largest number & smallest number in array
- C++ - Find largest character in string
- C++ - Sort string of characters in ascending order
- C++ - Sort string of characters in descending order
- C++ - Find smallest character in string
- C++ - Find second largest character in string
- C++ - Find second smallest character in string
- C++ - Check if string is palindrome
- C++ - Find sum of largest number & smallest number in array
- C++ - Check if string is in alphanumeric
- C++ - Check if string is in uppercase
- C++ - Check if string is in lowercase
- C++ - Check if string is in numeric
- C++ - Check if string contains only alphabets
- C++ - Reverse every word of a string
- C++ - identify missing character in string
- C++ - Print Fibonacci series up to N
- C++ - Find quotient & remainder
- C++ - Convert decimal number to binary
- C++ - Convert binary to decimal number
- C++ - Print number & string entered by user
- C++ - Check whether number is prime or not
- C++ - Find LCM of two numbers
- C++ - Find GCD of two numbers
- C++ - Print table of number entered
- C++ - Find sum of adjacent elements of array
- C++ - Find product of adjacent elements of array
- C++ - Find difference of adjacent elements of array
- C++ - Find occurrence of number in array
- C++ - Find most occurring element in an array of integers
- C++ - Separate even & odd numbers in array
- C++ - Find sum of even & odd numbers of array
- C++ - Find product of even & odd numbers of array
- C++ - Search an element in array
- C++ - Sort array in even-odd form
- C++ - Merge two arrays
- C++ - Add two arrays
- C++ - Find product of two arrays
- C++ - Find sum of two arrays one in reverse
- C++ - Find product of two arrays one in reverse
- C++ - Check whether matrix is an identity matrix or not
- C++ - Check if matrices are equal or not
- C++ - Find sum of each row of matrix
- C++ - Check whether matrix is a sparse matrix or not
- C++ - Find sum of both diagonals of matrix
- C++ - Find product of both diagonals of matrix
- C++ - Find product of each row of matrix
- C++ - Find subtraction of two matrices
- C++ - Delete an element of an array
- C++ - Insert an element of an array
- C++ - Check if number is ugly or not
- C++ - Print ugly numbers in a range
- C++ - Check if number is abundant or not
- C++ - Print abundant numbers in a range
- C++ - Check if number is deficient or not
- C++ - Print deficient numbers in a range
- C++ - Check if number is kaprekar or not
- C++ - Print kaprekar numbers in a range
- C++ - Check if number is narcissistic or not
- C++ - Print narcissistic numbers in a range
- C++ - Check if number is happy or not
- C++ - Print happy numbers in a range
- C++ - Check if number is disarium or not
- C++ - Print disarium numbers in a range
- C++ - Check if number is pronic or not
- C++ - Print pronic numbers in a range
- C++ - Check if number is automorphic or not
- C++ - Print automorphic numbers in a range
- C++ - Convert number from integer to roman
- C++ - Convert number from roman to integer
- C++ - Find sum of each column of matrix
- C++ - Find product of each column of matrix
- C++ - count total occurrences of each element in an array
Home » C++ programs » C++ basic programs
C++ program to read string using cin.getline()Learn, how can we read a string using cin.getline() in C++? [Last updated : March 01, 2023]
Reading string using cin.getline()
Since cin does not read complete string using spaces, stings terminates as you input space. While cin.getline() – is used to read unformatted string (set of characters) from the standard input device (keyboard). This function reads complete string until a give delimiter or null match.
cin.getline() Example in C++
In this program will read details name, address, about of a person and print in different lines, name will contain spaces and dot, address will contain space, commas, and other special characters, same about will also contains mixed characters. We will read all details using cin.getline() function and print using cout.
C++ code to read string using cin.getline()
/*C++ program to read string using cin.getline().*/ #include <iostream> using namespace std; //macro definitions for maximum length of variables #define MAX_NAME_LENGTH 50 #define MAX_ADDRESS_LENGTH 100 #define MAX_ABOUT_LENGTH 200 using namespace std; int main() { char name[MAX_NAME_LENGTH],address[MAX_ADDRESS_LENGTH],about[MAX_ABOUT_LENGTH]; cout << "Enter name: "; cin.getline(name,MAX_NAME_LENGTH); cout << "Enter address: "; cin.getline(address,MAX_ADDRESS_LENGTH); cout << "Enter about yourself (press # to complete): "; cin.getline(about,MAX_ABOUT_LENGTH,'#'); //# is a delimiter cout << "\nEntered details are:"; cout << "Name: " << name << endl; cout << "Address: " << address << endl; cout << "About: " << about << endl; return 0; }Output
Enter name: Mr. Mike Thomas Enter address: 101, Phill Tower, N.S., USA Enter about yourself (press # to complete): Hello there! I am Mike, a website designer. My hobbies are creating web applications.# Entered details are:Name: Mr. Mike Thomas Address: 101, Phill Tower, N.S., USA About: Hello there! I am Mike, a website designer. My hobbies are creating web applications. C++ program to demonstrate function overloading C++ program to generate random numbers Advertisement AdvertisementRelated Programs
- C++ program to print "Hello World"
- Read character array as string using cin in C++
- C++ program to demonstrate cascading cout & cin
- C++ program to demonstrate use of Resolution Operator(SRO), Use global variable in local scope
- C++ program to demonstrate use of reference variable
- C++ program to use function as a LVALUE using reference variable
- C++ program to demonstrate Inline Function
- C++ program to demonstrate Default Argument
- C++ program to demonstrate methods of passing in function
- C++ program to demonstrate function overloading
- C++ program to generate random numbers
- Print Reverse Triangle Bridge Pattern for Characters in C++
Comments and Discussions!
Load comments ↻
Advertisement Advertisement AdvertisementTop MCQs
- Marketing MCQs
- Blockchain MCQs
- Artificial Intelligence MCQs
- Data Analytics & Visualization MCQs
- MIS MCQs
- C MCQs
- C+ MCQs
- Python MCQs
- Java MCQs
- Excel MCQs
Top Programs/Examples
- C Programs
- C++ Programs
- Python Programs
- Java Programs
- D.S. Programs
- Golang Programs
- C# Programs
- JavaScript Examples
- jQuery Examples
- CSS Examples
Top Tutorials
- C Tutorial
- C++ Tutorial
- Python Tutorial
- ML/AI Tutorial
- MIS Tutorial
- Software Engineering Tutorial
- Scala Tutorial
- More...
About
- About us
- Contact us
- Privacy policy
Student's Section
- Internship
- Certificates
- Content Writers of the Month
Subscribe
- Telegram
Copyright © 2025 www.includehelp.com. All rights reserved.
Join us on Telegram ✖Tag » How To Use Getline In C++
-
Getline In C++ - GeeksforGeeks
-
An Introduction To C++ Getline With Syntax And Examples - Simplilearn
-
Std::getline - C++
-
How To Use Std::getline() In C++? - DigitalOcean
-
Getline In C++ – Cin Getline() Function Example - FreeCodeCamp
-
C++ Getline() - Javatpoint
-
11.2: C++ Input- Getline() - Engineering LibreTexts
-
Std::getline
-
Learn How To Use Getline C++ String In No Time - BitDegree
-
C++ Getline() | Learn The Examples Of The Getline( ) Function In C++
-
Getline C++ Explained With Examples - Udacity
-
C++ Program To Read String Using tline() - TutorialAndExample
-
Getline Library Function In C++ | Edureka
-
C++ Getline Function | Reading An Entire Line From Streams - YouTube