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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:39:33+00:00 2026-06-02T22:39:33+00:00

This is my first time posting so bear with me. I have a file

  • 0

This is my first time posting so bear with me.

I have a file that I need to read the header in via redirection and I’m using cin to capture the bytes and store them for later use.

The hexdump for the file is:

42 02 02 02 ff 0a 00 00  00 19 00 00 00 ff

What I have:

char magic, cs1, cs2, cs3, selector;
char temp1, temp2, temp3, temp4;
cin >> magic;
cin >> cs1;
cin >> cs2;
cin >> cs3;
cin >> selector; 
//   
cin >> temp1;
cin >> temp2;
cin >> temp3;
cin >> temp4;

The first 5 bytes represent magicNumber, channelSize, channelSize, channelSize, selectorBit.
The next 4 bytes are a width value separated into 4 bytes in LSB to MSB.

When I use cin on 0a which is 10 in hex (the value I want) it reads it as a newline character and thus skips it.

cout << temp1 << endl;
cout << temp2 << endl;
cout << temp3 << endl;
cout << temp4 << endl;

This will contain (in hex):

0
0
0
19

cin skips over 0a and grabs the next value. Is there a way to force it to read 0a?

If any more info is needed, let me know. Thanks

— Kyle

  • 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-02T22:39:35+00:00Added an answer on June 2, 2026 at 10:39 pm

    This is because cin, which is an istream expects the data to be text.

    If you are working with binary data then istream::get and istream::read are what you are looking for.

    std::cin.get(temp1)
    std::cin.get(temp2)
    std::cin.get(temp3)
    std::cin.get(temp4)
    

    Retrieves four byte values from the input stream.

    char buff[4];
    std::cin.read(buff, 4);
    

    Will read the block of data into an array of chars for you. You could use a plain integer
    if the endianness matches that of the data.

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

Sidebar

Related Questions

this is my first time posting on here and have read alot of helpful
this is my first time posting here, I have a question which I have
That's my first time posting on stackoverflow. I've been finding usefull answers on this
I am doing this first time so I need some help. I am using
This is my first time posting to stackoverflow, but these threads have helped me
First time posting, please bear with me. I'm trying to create a slideshow that:
this is my first time on posting so if I have done anything please
This is my first time posting on stackoverflow so bear with me. I decided
this is my first time posting on StackOverflow but this site is awesome. Thanks
use this website a lot but first time posting. My program creates a number

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.