Explains the number of methods from which we can take the string input from the user.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
C++ Programming Question
Explains the number of methods from which we can take the string input from the user.
Transcribed Image Text:C++ Programming Question Explains the number of methods from which we can take the string input from the user.
Expert Solution
Step 1

There are some methods that are used to take the string input from user. Let's discuss it.

Method1.

you can create a character array for multiple strings.

for example:- char a[size];

Now, you can input a string in the form of array. In the character array, when you enter the string that will be a sequence of characters and each character will be element of the array. In which the string will end with a special character that is \0.  So, you can put it at the end of the character.

Method2.

you can use cin.get() method that accepts the character with whitespace. So, it reads the string with whitespace. you can enter the string character by character using loop.

for example:- cin.get(string name, size);

Method3.

you can use gets() method to take user input that reads the character from stdin and stores them in str until a newline character is found.

for example:-  gets(str); 

Method4.

you can use cin.getline() method that is used to read unformatted string means set of characters from the keyboard(standard input device).

for example:- cin.getline(<character array>, size);

Method5.

you can use simple cin method with extraction operator >> to take a string input from the user. But it doesn't allows the whitespace.  Whitespace is a delimiter for cin.

for example:- cin>>enter name;

There are another method in c++  provides us with the header file <cstring>. By this file, you can find lot of predefined functions for string. You can create variables of string data type by the header file.

 

                       

 

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Methods of StringBuilder class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education