If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
C++ में cin और double greater than >> की help से user input को capture किया जाता है। आप जिस type की value keyboard से enter करेंगे automatically आपको उसी type में मिल जायगी।
#include <iostream>
using namespace std;
int main() {
int number1, number2;
cout << "Enter first number : ";
cin >> number1;
cout << "Enter second number : ";
cin >> number2;
cout << "Addition : " << number1 + number2;
return 0;
}
Enter first number : 12 Enter second number : 23 Addition : 35
same इसी तरह से आप string या other type की value भी capture कर सकते हैं।
हालाँकि , अगर आप space देते हैं तो वो capture नहीं हो पाएगा , सिर्फ वही input मिलेगा जहाँ तक space नहीं है -
#include <iostream>
using namespace std;
int main() {
string full_name;
cout << "Enter full name : ";
cin >> full_name;
cout << "Fullname : " << full_name;
return 0;
}
Enter full name : Rahul kuamr Fullname : Rahul
तो जैसा कि आप example में देख सकते हैं कि , space के बाद का input capture नहीं हुआ है , इस problem को resolve करने के लिए हम getline() function का use करते हैं।
#include <iostream>
using namespace std;
int main() {
string full_name;
cout << "Enter full name : ";
// use getline() to capture whole input line.
getline(cin,full_name);
cout << "Fullname : " << full_name;
return 0;
}
Enter full name : Rahul Kumar Fullname : Rahul Kumar
I Hope, अब आपको C++ में user input अच्छे से समझ आ गया होगा।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook