Asked Nov 24, 2019

What are strings in c++?


Expert Answer

Step 1

String in C++:

String is a class found in the library of C++. String object is used to store the strings.

The string object describes a series of characters. Character arrays are also used to store string, but the basic difference between the string object and the character array is that the length of the string objects is not fixed and can be prolonged as per the need of the program.

The string object is found in the <string> class.


//string class

#include <string>

//main method

main() method


//string object is declared

string <string_name>;


Step 2

Below are some operations that are used perform some action on the strings:

  • getline(): This function is used to store a sequence or stream of characters into the memory of object entered by the user.   
  • length(): This function is used to calculate the length of a string.
  • resize(): This function is used to change the size of a string dynamically either increase it or decrease.
  • clear(): This function...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in


Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add

Q: Question in Image. I was wondering why they are not equal even thought their contents are the same

A: Code:


Q: Can you think about situations where range controls and null value controls will improve data integr...

A: Situations where range controls and null value controls will improve data integrity: Range controls ...


Q: In Python Define a function writeScores with two parameters. The first should be the name of a file,...

A: Below is the approach and python code:Approach:Define a function “writeScores” having two parameters...


Q: What are different datatypes used in c?

A: Definition of data type –Data types in C language are used to declare functions or to declare variab...


Q: consider the UDP header 12 03 00 0f 00 1e 10 wha tis the total length of the UDP ? (A) 32 bytes (b) ...

A: The UPD header basically has 4 parts, each part is of 2 bytes. That means following interpretation o...


Q: i need to read a list in a text file and then print it... in python

A: Program Instructions:Take a file, in here the name of the file is “example.txt” and it contains some...


Q: Given a nested list named table, use a loop to print each sub list of the nested list. The sub lists...

A: Program descriptionOne 3 x3 list is created to demonstrate the conceptdisplay the elements of the su...


Q: I have this project where I create a program that calculates the area of a rectangular prism. I am s...

A: Create a JAVA class Prismarea which contains a method calcArea() and instance variable “a” to store ...


Q: Create a class of students that should contain fields like rollno,name,subject and marks?

A: Programming language assumed is C++:Class:A C++ class is the building block, which contributes to th...