c++ string

c++ string


In this tutorials you are going to learn c++ string , what is string how to define a string 

so let start today c++ string tutorial.

you can read our previous C++ Tutorials.

introduction to c++

c++ array

structure of c++ program

c++ string
c++ string

c++ string

String is collection of alphabetical characters  . Like other  data types , strings can be variable or consts. Here is a simple program that defines a single string variable. This simple program will take input from user, and then it will place in string variable . Then it will display the string .

Simple Program of c++ string

Save it as String.cpp


Program’s Explanation:

In first statement


we declare a int type MAX variable to store 50 characters of string.

In 2nd statement ,  char std[MAX];

We define a string, name of string is std, all strings’s characters will  be store in it .


This simple statement will print a message on screen. Enter Your String


in this statement operator >> is  ,which is also called extraction operator , use to read a string from keyboard and then it will  place it in the string  variable which we declare as  std.

Insertion  operator ( >>)  knows how to deal with strings; it understand that they are arrays of characters . Each characters in string take 1 byte of memory . An important aspect of strings is that they must terminate with a byte containing 0. This is frequently characterized by characters constant 0, which is a characters with an ASCII value of 0. This terminating zero is called null characters. When the (<<) operator shows string, it displays characters till it meets null character .


Sting Constant in C++

You can also initialize a string to a constant value when you define it. 

Program for constant   c++ string


Program’s explanation :


in this statement we define a string, then we initialize it with constant string .

This statement


will simply print a string on screen.


Keep visiting our site, more content about String will be upload.



Leave a Comment