Guest

cin ignore

Jan 9th, 2026
14
0
Never
Not a member of gistpad yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | Source Code | 0 0
  1. // SpiderX Code
  2.  
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int age;
  10. string fullName;
  11.  
  12. // 1. Pehle hum number input lete hain
  13. cout << "Enter Age: ";
  14. cin >> age;
  15.  
  16. // YAHAN HAI MAGIC LINE
  17. // cin buffer mein se 'Enter' (\n) ko hatane ke liye
  18. cin.ignore();
  19.  
  20. // 2. Ab hum string input lete hain (jo space ke sath ho sakti hai)
  21. cout << "Enter Full Name: ";
  22. getline(cin, fullName);
  23.  
  24. // Show Output
  25. cout << "\n--- Result ---" << endl;
  26. cout << "Age: " << age << endl;
  27. cout << "Name: " << fullName << endl;
  28.  
  29. return 0;
  30. }
RAW Gist Data Copied