JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

C++ : String Input or Output Operation in hindi , what is input and output operation in string programme in c++ language

what is input and output operation in string programme in c++ language , C++ : String Input or Output Operation in hindi :-
String मे input और आउटपुट operation को समजने के इए निन्म उदाहरण को consider करेगे |
#include<stdio.h>
#include<conio.h>
void main()
{
using namespace std;
const int size = 30;
char name [size];
char name1[size];
cout<<“Enter Name”;
cin>>name;
cout<<“Enter Nick Name”;
cin>>name1;
cout<<“Nick name of “<<name << “is” << name1.;
getch();
}
इस उदाहरण मे , name को read और write किया गया है | इसमें यूजर के नाम और निक नाम को input किया जाता है और इससे name और name1 मे store किया जाता है | इसका आउटपुट होगा:
Enter Name : Harry
Enter Nick Name: Hansh
Nick name of Harry is Hansh.
Problem of cin Statement
cin statement के साथ एक प्रॉब्लम होती है cin statement कब terminate होगा क्योकि हमने string के value मे कोई null character को define नहीं किया है |लेकिन cin statement whitespace , newline और tab को string का end consider मान लेता है |
इसलिय cin statement से केवल एक word को read कर सकता है |जब cin statement एक word को पढ़ लेता है तब आटोमेटिक null character को insert कर देता है |
उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
void main()
{
using namespace std;
const int size = 30;
char name [size];
char place[size];
cout<<“Enter Name : “;
cin>>name;
cout<<“Enter Favorite Place :”;
cin>>place;
cout<<“Favorite Place of “<<name << “is” << place.;
getch();
}
इस उदाहरण मे , name को read और write किया गया है | इसमें यूजर के नाम और उसकी favorite palce  को input किया जाता है अगर यूजर द्वारा दिए गये नाम मे दो word होगे तो केवल एक ही word read होगा | इसका आउटपुट होगा:
Enter Name : Harry Watson
Enter Nick Name: Rocky Mountain Valley
Favorite Place of  Harry is Rocky.
User का पूरा नाम Harry Watson था लेकिन cin statement से केवल Harry को read किया गया क्योकि Harry के बाद space था |
String Reading (A line at a time)
किसी string से एक word को read करना बहुत उपयोगी नहीं होता है |जैसे किसी city के नाम को store करने के लिए cin statement उपयुक्त नहीं है | उदाहरण के लिए new delhi मे से केवल new ही read होगा | जब किसी string मे से line को read करने के लिए istream class मे से दो members होते है जिससे line को read किया जाता है |
1.getline () : इसका use string की line को read करने के लिए किया जाता है |
2.get():इसका use string की line को read करने के लिए किया जाता है |
getline() :
getline() का use पूरी line को read करने लिये किया जाता है | ये member तब तक string को read करता है जब तक new line charecter नहीं आ जाता है | इस member को प्रोग्राम मे निन्म तरीके से include किया जाता है :
cin.getline(string,size);
यहा पर :
cin: ये cin class को define करता है | getline() : ये class member है |
इस function मे दो argumnet pass होते है |
1.string : ये string का नाम है जिसमे data को read करके assign करना होता है |
2.size : ये function द्वारा read किये जाने वाले character की size को define करता है |
उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
void main()
{
using namespace std;
const int size = 30;
char name [size];
char place[size];
cout<<“Enter Name : “;
cin.getline(name);
cout<<“Enter Favorite Place :”;
cin.getline(palce);
cout<<“Favorite Place of “<<name << “is” << place.;
getch();
}
इस उदाहरण मे , name को read और write किया गया है | इसमें यूजर के नाम और उसकी favorite palce  को input किया जाता है अगर यूजर द्वारा दिए गये नाम मे दो word होगे तो दोनों ही words read होगा | इसका आउटपुट होगा:
Enter Name : Harry Watson
Enter Nick Name: Rocky Mountain Valley
Favorite Place of Harry Watson is Rocky Mountain Valley.
get()
ये एक member function है जिसे string को read करने के ल्लिये किया जाता है | इसका use getline() की तरह होता है| इसमें दो parameter pass होता है | ये भी string को तब तक read करता है जब तक string मे new लिनव character नहीं आ जाता है |लेकिन ये new line को read करने के बजाए इससे discard कर देता है | और get() function बाकि बचे हुआ character को terminate कर देता है |
उदाहरण के लिए
get(name,4);
get(place);
इस statement से error आएगी क्योकि पहले statement से character input queue मे रहज जाती है |इस प्रॉब्लम को solve करने के लिए get() function को use किया जाता है लेकिन ये get() function null होती है |
cin.get();
इस statement से cin का control next line पर चला जाता है |अगर कोई character input queue मे remaining होता है तब ये operation होता है  |
उदाहरण के लिए
cin.get(name,4);
cin.get();
get(place,30);
एक दूसरा तरीका भी होता है इस प्रॉब्लम को solve करने के लिए | class member को निन्म तरीके से call करने पर भी प्रॉब्लम solve हो जाती है |
cin.get(name , size).get;
अतः get () function को merge भी कर सकते है |उदाहरण के लिए
cin.get(name , 20).get(name1,20);
get() function उदाहरण के लिए
#include<stdio.h>
#include<conio.h>
void main()
{
using namespace std;
const int size = 30;
char name [size];
char place[size];
cout<<“Enter Name : “;;
cout<<“Enter Favorite Place :”;
cin.get(name,30).get(palce,30);
cout<<“Favorite Place of “<<name << “is” << place.;
getch();
}
इस उदाहरण मे name और place को एक साथ एक ही statement मे read कर दिया गया है |जिससे प्रोग्राम मे space भी कम हो जाता है | इसका आउटपुट होगा :
Enter Name : Rahul Gupta
Enter Nick Name: Jal Mahal
Favorite Place of Rahul Gupta is Jal Mahal .
Empty Line Problem
जब getline () और get () function कोई empty line को read करता है तब इन function  के द्वारा failbit की condition set हो जाती है |इसमें input block हो जाता है जब तक की input को रिस्टोर नहीं किया जाता है |इसके लिए निन्म member function को use किया जाता है |
cin.clear();
इसके अलावा दूसरी प्रॉब्लम होती जब input string की size ,allocate memory से बड़ी होती है |जब input string की size allocate memory से बड़ी होती है तब get() और getline function input string मे से बाकि के character को छोड़ देता है | या getline () मे failbit की condition आ जाती है और फुठेर input को बंद कर देता है |
इस article मे string को read करने के लिए तीन तरीके cin, get() और getline को discuss किया है | आगे आने वाले article मे string class को discuss करेगे |
Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

23 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

4 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

6 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now