Thanks to visit codestin.com
Credit goes to www.scribd.com

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

T8U5 String Attributes

The document describes various attributes of strings in programming, including size, capacity, length, emptiness, substring finding, and string comparison. It explains how to use member functions to obtain these attributes and provides a sample program demonstrating their usage. The output of the program shows the size, capacity, emptiness, substring position, and comparison result of two strings.

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)
13 views2 pages

T8U5 String Attributes

The document describes various attributes of strings in programming, including size, capacity, length, emptiness, substring finding, and string comparison. It explains how to use member functions to obtain these attributes and provides a sample program demonstrating their usage. The output of the program shows the size, capacity, emptiness, substring position, and comparison result of two strings.

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 Attributes

· The various attributes of a string such as

· SIZE , length , and capacity, empty , find,substring,compare can be obtained using member
functions.

SIZE

· The size of the string indicates the total number of elements currently stored in the string.

capacity

· The capacity means the total numbers of elements that can be stored in a string.

· the maximums size means the largest valid size of the string supported by the system.

length

· The member function length() determines the length of the string object , that is , the number of
characters present in the string.

empty

· The empty function determines whether the strin is empty or filled. If the string is empty , it
returns 1 , otherwise it returns 0 .

find

· The find member funtion finds the given sub-string in the main string.

compare

The member function compare is used to compare two strings or sub-string. It returns 0 when the two
strings are similer , otherwise , it returns a non-zero value

Write a program for string attributes

#include<iostream.h>

#include<conio.h>

void main()

clrscr();
string s1;

s1="Hello";

s2="hello";

cout<<"\n Size of s1 is:"<<s1.size();

cout<<"\n capacity s1 is:"<<s1.capacity();

cout<<"\n S1 is empty:"<<s1.empty();

cout<<"\n find llo in hello:"<<s1.find("llo");

cout<<"\n compare string is:"<<s1.compare(s2);

getch();

OUTPUT

Size of s1 is: 6

capacity s1 is: 31

S1 is empty : 0

find llo in hello : 1

compare string is: false

You might also like