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

  • Home
  • SEARCH
  • 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 7648073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:37:16+00:00 2026-05-31T10:37:16+00:00

note: this is in C++ but using C-style strings hello SO, I’m working on

  • 0

note: this is in C++ but using C-style strings

hello SO,

I’m working on an assignment and I need to get input from the console and save it to a cstring. Everything compiles fine, but when the program runs, it just skips over getting input from the user. So it will output: "Enter string to be inserted: " then skip the cin.getline function, then execute the next command.

Here’s my header files, the declaration of the cstring, and the line of code I’m having trouble with.

#include "stdafx.h"
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
  char tempCString[500] = {};

//...code snipit...

  cout << "Enter string to be inserted: " << endl;
  cin.getline(tempCString, 500, '\n'); //I've also tried cin.getline(tempCString, 500);

//...end code snipit...

  return 0;
}

note: I can’t use "cin >> tempCString" becaues it will only get the input up to the first space, I need to get input from the console of everything up to the newline.

Thank you

  • 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-05-31T10:37:18+00:00Added an answer on May 31, 2026 at 10:37 am

    Try clearing cin‘s buffer before getting new input:

    #include <limits>
    
    cin.clear();
    cin.ignore(std::numeric_limits<std::streamsize>::max());
    cout << "Enter string to be inserted: " << endl;
    cin.getline(tempCString, sizeof(tempCString), '\n');
    

    See How do I flush the cin buffer?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This is similar to this question but it is not the same. I
Note: this question is related to this one , but two years is a
Note: I know this is wrong , but this is a technical requirement by
NOTE: I have solved the majority of this problem but have run into a
[Note: There is another thread about this problem but it did not answer the
Note: I asked this yesterday over at kiln.stackexchange.com , but haven't gotten an answer,
Note: I've asked this question in a similiar format on superuser but it seems
Note: I'm not a newb, and I've done this a gazillion times, but for
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
[Note: This question had the original title " C (ish) style union in C#

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.