C++ : String , what is string in c++ language in hindi , examples स्ट्रिंग computer programming in hindi

examples स्ट्रिंग computer programming in hindi , C++ : String , what is string in c++ language in hindi :-
इससे पहले के article मे , compound data type मे से array को discuss किया गया था |अब इस article मे string : array का दूसरा type को discuss किया जायेगा | string किसी programming language का महतवपूर्ण data type है || जिसमे किसी variable का नाम , message आदि  को store कर सकता है |
String
string character की series होती है जो की continuous memory space मे store होती है |C++ मे दो प्रकार से string को handle कर सकते है :
1.C Style string
2.String Class
इस article मे C Style string को discuss करेगे |और string class को class chapter मे discuss करेगे |
C Style string
जब string को implementation को सोचा है तब पता चलता है की string , character का array होता है | और प्रत्येक character  array के index पर store होगा | String का use किसी text information को store करने के लिए किया जाता है | जैसे
Please Enter your bank account :
Account does not exits.
C Style string का एक feature होता है : string का last element null element होता है | Null character ‘/0’ को define किया जाता  है |जिसकी ASCII value ‘0’ होती है |इसका मतलब string का end को define करता है | उदाहरण के लिए :
char name [6] = { ‘p’ ,’a’,’r’,’t’,’h’}; ये string नहीं है |
char name [6] = { ‘p’ ,’a’,’r’,’t’,’h’,’\0′}; ये string  है क्योकि इसके end null character को introduce किया जाता है |
दोनों ही उदाहरण मे character की array है लेकिन दूसरा array string भी है |
उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
char name[6]=”Parth”;
cout<<“Name : “<< name << endl;
getch();
}
C++ मे कई सारे function होते है जिससे string को handle किया जाता है |ये function string मे character wise अप्लाई होते है जो की तब तक apply होते है जब तक null वत्रिअब्ले नहीं आ जाता है |
अगर cout का use , name [] string को display करने के लिए जाता है तब ये first छ character को display करेगे | ये null character को consider करेगा | अगर cout का use कसी array को display कर्ण एके लिए किया जाता है तब ये पांच character को display करेगा |
 
String Initial
string को declare करनेके बाद initial किया जाना complusy होता है | string को इन्तिअल करना के दो method होते है |
1.पहले प्रकार मे , string value को ब्रैकेट मे लिखा जाता है | जिसमे प्रत्येक character को single quote मे क्लोज किया जाता है | Bracket का last element हमेशा null character होता है | लेकिन ये तरीका छोटी length के string के लिए possible होता है |
उदाहरण
#include<iostream.h>
#include<conio.h>
void mian()
{
char name[6]={ ‘p’ ,’a’,’r’,’t’,’h’,’\0′};
cout<<“Name : “<< name << endl;
getch();
}
इस उदाहरन मे parth को string name मे assign किया गया हो | {} का last element null element है |
2.दुसरे प्रकार मे , string को initial करने के लिए string value को double quote मे क्लोज किया जाता है |इस method मे null character को लिखना जरुरी नहीं है | ये तरीका सबसे better होता है | क्योकि string की value की length का initial पर कोई effect नहीं पड़ता है |
उदहारण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
char string[37]= “i am boy ! My name is Parth. Hello !”;
cout<<“Name : “<< name << endl;
getch();
}
इस method की एक और feature है की string value की length , string size से छोटी हो सकती है | उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
char string[10]= “parth ! “;
cout<<“Name : “<< name << endl;
getch();
}
इस उदाहरण मे string की size 10 है लेकिन initial string value की length  7 है |इस condition मे , index 8,9,10 पर null character insert हो जाता है |
 
String Constant
किसी string को constant की तरह use किया जा सकता है | इसके लिए string name से पहले static keyword को use किया जाता है |
उदाहरण के लिए :
static char size[] = “A”;
यहा पर size एक string जिसमे दो charecter ,’A’ और null character store होगा | अगर प्रोग्रामर character की ASCII value को use करना चाहता है तब इसे निन्म declaration करना होगा :
static char size[] = ‘A’;
 
String Constant Concatenating
जब कोई string बहुत बड़ी होती तब इसे एक line मे लिखना मुश्किल हो जाता है |इसलिए C++ मे string concatenating का feature होता है |जो की दो string ( जो की single quote मे क्लोज होती है ) combine हो जाती है | दोनों string के बीच white space introduce हो जाता है |
उदाहरण के लिए :
cout<<“I am boy. My name is Rahul Gujar . I completed “
“B.tech in rajasthan technical university.\n”;
उपर दिया code से निन्म आउटपुट display होगा |
I am boy. My name is Rahul Gujar . I completed B.tech in rajasthan technical university.
उपर दिए code को निन्म तरीके से लिख सकते है जिससे आउटपुट पर कोइ effect  नहीं पड़ता |
cout<<“I am boy. My name is Rahul Gujar . I completed B.tech in rajasthan technical university.\n”;
String in array
string को array मे दो तरीके से use किया जाता है |
1.string को array के initial मे declare किया जाता है |
इस प्रकार मे array के initial मे , string को single quote मे assign किया जाता है |और cin statement से input की गयी string को array मे assign करना | इसके लिए strlen() : जो की string की length को calculate करता है | को use किया जाता है | इसके लिए cstring.h header file को use किया जाता है |
2.File और  keyboard को array के input मे define करना |
उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
using name space std;
const int size =30;
char string1[size];  // string declare //
char string2[size]=”Super”;  // array declare //
cout<<“! I am “<<string2;
cout<<“Who are You ?”<<endl;
cin>>string1;
cou<<“Length of String”<<strlen(string1)<<endl;
Cout<<“Size of array”<<sizeof(string1)<<endl;
cout<<“First Letter of name “<< string1[0]<<;
string2[3]=’/0′;
cout<<“First three letter of my name:  “<<string2<<endl;
getch();
}
आउटपुट होगा :
i am Super
Who are You ? Parth
Length of String 5
Size of array 10
First Letter of name : P
First three letter of my name: Sup
इस article मे ,string का basic को discuss किया है | अब C++ : String Input और Output operation मे string मे input और output statement को discuss करेगे |