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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:31:08+00:00 2026-05-25T21:31:08+00:00

How would I go about taking input for seekp and put for use with

  • 0

How would I go about taking input for seekp and put for use with hex? Something like this?
Cin>>hex>>mychar;

How about printing the correct value in hex?
Say at 0x16 the byte is FF or 255 unsigned 8bit(decimal?) when I do this

fstream mystream;
mystream.seekp(0x16);
long myvar;
myvar=mystream.tellp();
cout<<"Value at offset 0x16: "<<myvar;

It prints 22 im assuming since I opened the file in binary mode thats why its printing 22 as the value of FF in binary is like 2222222 etc.

Is there a correct data type for printing the value at a certain offset(I’ve tried long and char and int but it still yields 22.) or am I printing them wrong? I’ve searched on google but couldnt find any help in this regard however I did note that opening the file in binary is recommended for editing with hex.

  • 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-25T21:31:09+00:00Added an answer on May 25, 2026 at 9:31 pm

    There are a couple of problems with your code:

    • ostream::seekp sets the “put” pointer, i.e. the location at which one writes data, not the position at which one reads data. Use istream::seekg to set the “get” pointer
    • ostream::tellp doesn’t perform any I/O. It merely reports the value of the ‘put’ pointer, it doesn’t actually fetch the data stored there. You mean to use istream::get.

    Your program is printing the decimal number 22, which is equal to the hexadecimal number 0x16. That is because seekp sets the put pointer to 0x16, and tellp merely reports the value of the put pointer — 0x16!

    Try this code:

    fstream mystream;
    mystream.seekg(0x16);
    int myvar;
    myvar=mystream.get();
    cout<<"Value at offset 0x16: "<<myvar << "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using QT, how would I go about taking user-supplied input (text) and drawing the
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
Just a quick question about how you would go about implementing this. I want
I would like to know how I would go about altering the HTML that
I would like to convert a string input representing numbers to the respective numeric
If my html looked like this: <td class=controlCell> <input class=inputText id=SearchBag.CompanyName name=SearchBag.CompanyName type=text value=
Any ideas how I would go about writing a javascript method to insert an
I'm wondering how you would go about designing a good permgen space string in
I'm wondering how i would go about making the following application: a user signs
Anyone have any idea how I would go about converting a timestamp in milliseconds

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.