C++ PROGRAM
STRING
BY:B.DHEENADAYALAN
STRING
String is a sequence of character or collection of character or array of
Character.
CHARACTER:
★ It represent a single letter within the single codes.
★ Example: ‘h’,’e’,’l’,’l’,’o’.
STRING:
★ It represent a collection of character within double codes.
★ Example:”hello”.
TYPES OF DECLARATION:
C++ provides following two types of string representations:
● The C-style character string.
● The string class type introduced with Standard c++
C STYLE DECLARATION SYNTAX:
● char string_name [size of the string];
STANDARD C++ DECLARATION SYNTAX:
● string name[size of the string];
INITIALIZATION:
● Using single character constant eg: string s1={‘h’,’e’,’l’,’l’,’o’,’0’};
● Using string constant eg: string s2={“hello”};
● String s3=s2; copy initialization
● String s4(s1); direct initialization
● String s5(6,’d’);  concatenates
● String s6;
cout<<”enter the string”;
cin>>s6;
cout<<”you entered”<<s6;  string was choosed by the user.
● length = s6.size();
cout<<length;  to identify the size.
Memory Presentation :
●
SOME OF THE FUNCTION AND PURPOSE :
1. strcpy(s1, s2); Copies string s2 into string s1.
2. strcat(s1, s2); Concatenates string s2 onto the end of string s1.
3. strlen(s1); Returns the length of string s1.
4. strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than
if s1<s2; greater than 0 if s1>s2.
5.strchr(s1, ch); Returns a pointer to the first occurrence of
character ch in string s1.
6.strstr(s1, s2); Returns a pointer to the first occurrence of string
s2 in string s1.
THANK YOU!

C++ string

  • 1.
  • 2.
    STRING String is asequence of character or collection of character or array of Character. CHARACTER: ★ It represent a single letter within the single codes. ★ Example: ‘h’,’e’,’l’,’l’,’o’. STRING: ★ It represent a collection of character within double codes. ★ Example:”hello”.
  • 3.
    TYPES OF DECLARATION: C++provides following two types of string representations: ● The C-style character string. ● The string class type introduced with Standard c++ C STYLE DECLARATION SYNTAX: ● char string_name [size of the string]; STANDARD C++ DECLARATION SYNTAX: ● string name[size of the string];
  • 4.
    INITIALIZATION: ● Using singlecharacter constant eg: string s1={‘h’,’e’,’l’,’l’,’o’,’0’}; ● Using string constant eg: string s2={“hello”}; ● String s3=s2; copy initialization ● String s4(s1); direct initialization ● String s5(6,’d’); concatenates ● String s6; cout<<”enter the string”; cin>>s6; cout<<”you entered”<<s6; string was choosed by the user.
  • 5.
    ● length =s6.size(); cout<<length; to identify the size. Memory Presentation : ●
  • 6.
    SOME OF THEFUNCTION AND PURPOSE : 1. strcpy(s1, s2); Copies string s2 into string s1. 2. strcat(s1, s2); Concatenates string s2 onto the end of string s1. 3. strlen(s1); Returns the length of string s1. 4. strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than if s1<s2; greater than 0 if s1>s2. 5.strchr(s1, ch); Returns a pointer to the first occurrence of character ch in string s1. 6.strstr(s1, s2); Returns a pointer to the first occurrence of string s2 in string s1.
  • 7.