0% found this document useful (0 votes)
0 views2 pages

T7U5 Declaring and Intialization String

The document explains how to declare and initialize string objects in C++ using various constructors. It provides examples of creating empty strings, strings from character arrays, and string assignments and concatenations. Additionally, it includes a sample program demonstrating these concepts with input and output results.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

T7U5 Declaring and Intialization String

The document explains how to declare and initialize string objects in C++ using various constructors. It provides examples of creating empty strings, strings from character arrays, and string assignments and concatenations. Additionally, it includes a sample program demonstrating these concepts with input and output results.

Uploaded by

joyalprincess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

String Declaring and intializing string objects

· The string object declaration and intialization can be done once by using a constructor of the
string class.

Constructor Meaning

string() ; produces an empty string

string(const char *text) produces a string object from a null-ended string

string(const string & text) produces a string object from another string obj

we can declare and intialize string object as follows :

string text ; // using constructors without arguments

string text("C++") ; // using constructors with one argument

text1=text2 ; // Assignment of two string objects

text="C++" + text1 // concatenation of string objects

cin>>text // reading string without spaces through the keyboard

getline(cin,text) // reading string with blank page

Write a program for string objects

#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

clrscr();

string text;

string text("C++");

string text2("OOP");

cout<<"\n text1:"<<text1;
cout<<"\n text2:"<<text2;

text=text1;

cout<<"\n text:"<<text;

text=text1+" " +text2;

cout<<"\n now text:"<<text;

getch();

OUTPUT

text1: C++

text2: OOP

text : C++

now text : C++ OOP

You might also like