Easy learning with example program codes

CPP Strings

A sequence of characters, internally stored in the form of an array of characters is called as string.

Declaration of String:

In CPP, a string can be specified in two ways:

Character Array:

A string declared as an array, where each character represents an element of that array, is called as Character Array.


char array_Name[] = {char1,char2,char3………};

String Object:

To represent a sequence of characters, there is an object defined in std::string class, called as String Object.


string string_name = “stringValue”;

Example :

#include <iostream.h>  
using namespace std;  
int main( )
char chr[] = { 'H', 'E', 'L', 'L', 'O', ' ', 'C', 'P', 'P'};  
string str1 = "Hello CPP";    
string str2 = string(chr);    


Hello CPP       
Posted in CPP   
Sign Up/ Sign In
Ask a Question

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki