Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:09:56+00:00 2026-06-17T22:09:56+00:00

Possible Duplicate: c++ cin input not working? I have been trying to input a

  • 0

Possible Duplicate:
c++ cin input not working?

I have been trying to input a string after an integer using the following code in c++.

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
     int n;
     char inp[10];
     cin>>n;
     //fflush(stdin);
     cin.getline(inp,10);
     cout<<inp;
     return 0;
}

When i am compiling and running above code, the program is prompting for input only once and printing nothing. I am using g++ for compiling the code.
Also when i uncommented the line

fflush(stdin) 

(clearing input buffer), the o/p of program remains the same. I don’t understand what is going on here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:09:58+00:00Added an answer on June 17, 2026 at 10:09 pm
    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
    
     int n;
     char inp[10];
     cin>>n;
     cin.get();//cin.get(); just waits for enter. more approprate for this would be cin.ignore(); because it will flush the input stream for cin.
     cin.getline(inp,10);
     cout<<inp;
     // cin.get(); you could use this so your program wont return0 and close right away.
    return 0;
    }//tested in this config it works as desired, good luck
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Program not waiting for cin I wrote the following code: #include <iostream>
Possible Duplicate: Problem of using cin twice This code works but not what I
Possible Duplicate: Why isn’t cin >> string working with Visual C++ 2010? The first
Possible Duplicate: Need help with getline() getline not asking for input? I am working
Possible Duplicate: Best way to detect integer overflow in C/C++ i have tried to
Possible Duplicate: Read a password from std::cin I'm trying to make a simple password
Possible Duplicate: getline not asking for input? There is some unique thing happening in
Possible Duplicate: Using unique() on a vector of vectors in C++ I'm trying to
Possible Duplicate: Need help with getline() getline() is not working, if I use it
Possible Duplicate: C++ cin whitespace question I'm having problem trying to understand this piece

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.