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 8006587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:33:42+00:00 2026-06-04T17:33:42+00:00

input = new char[64](); std::cout << wait for cin << std::endl; while (std::cin >>

  • 0
input = new char[64]();
std::cout << "wait for cin" << std::endl;
while (std::cin >> std::setw(64) >> input)
{
    std::cout << "input : " << input << std::endl;
    ...

Well I assure you setw() copies 63 characters to the char * input instead of 64 and I see the 64rth character displayed on the next while(cin) iteration. Can this behavior be overridden ? I want all my 64 chars and NO nul in my array.

  • 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-04T17:33:44+00:00Added an answer on June 4, 2026 at 5:33 pm

    operator>>(istraem&, char*) will always write the nul byte.

    C++2003, 27.6.1.2.3/7 (emphasis added):

    Characters are extracted and stored until any of the following occurs:

    • n-1 characters are stored;
    • end of file occurs on the input sequence;
    • ct.is(ct.space,c) is true for the next available input character c, where ct is
      use_facet >(in.getloc()).

    Operator>> then stores a null byte (charT()) in the next position, which may be the first position if no
    characters were extracted. operator>> then calls width(0).

    You can get nearly the behavior you want

    • allocate a 65-byte array and call setw(65), or
    • call std::cin.read(input, 64).

    Note that the two solutions are not identical. Using std::cin >> input treats whitespace differently than std::cin.read() does.

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

Sidebar

Related Questions

I currently use: BufferedReader input = new BufferedReader(new FileReader(filename)); Is there a faster way?
In HTML5 there is a new input type, 'search'. On most browser it's just
If I have the following Java code: int[][] readAPuzzle() { Scanner input = new
My main method: public static void main(String[] args) { Scanner input = new Scanner(System.in);
I'm new to jQuery and I want to have a input box from a
i am new to iphone development. In my input date format is 2010-03-05T18:20:40Z, and
How can we intialize new google.maps.places.Autocomplete(Input, Options); for two text boxes in same page?
I am new to ruby. I need to receive password as an input through
my input String is : 2010-03-24T17:28:50.000Z output pattern is like: DateFormat formatter1 = new
I'm new. I've determined I cannot make a label active and accept keyboard input,

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.