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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:52:28+00:00 2026-05-22T21:52:28+00:00

I’m still working on that bitmap I/O problem from a week ago. I got

  • 0

I’m still working on that bitmap I/O problem from a week ago. I got stuck again, so I decided to start with a type of I/O I was familiar with, and make it more like what I needed steadily (which is checking each byte (pixel) at a time and outputting to a file based on that byte’s value).

I started out with a program that read and checked each character of a text file, and output a ‘Z’ if it was above some threshold and output an ‘A’ if it was below it.

That program worked great, so I decided to change it from characters to bytes in a file.

Now, I’ve been having problems with it. The first 26 (bytes 0-25) bytes of the file are correct, but the rest are 0 or -1, depending on whether I use ifstream.get() or ifstream.read.

The input file Input.FILE was made in a hex editor, and just contains 0x00-0xFF. It’s 256 bytes in length.

Code:

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main()
{
   ifstream sourcefile;
   ofstream output;
   ofstream output2;

   output.open("output.txt");
   output2.open("messages.txt");
   sourcefile.open("Input.FILE");

   vector<char> data(256);
   sourcefile.read(&data[0],256);
   sourcefile.seekg(0,ios::beg);

   for(int i = (int) 0x00 ; i < data.size() ; i++)
   {
      output2 << "Value data[" << i << "] = " << (int) data[i] << endl;

      if((int)data[i] < 0)
      {
         // since I can't make an unsigned char vector, I use this to convert
         // it to the correct number. Could this be the problem?
         data[i] = 256 + data[i];
         output2 << "less than zero." << endl;
      }

      if(data[i] > 64)
      {
         data[i] = 0xFF;
         output2 << "greater than 64, set to 0xFF." << endl;
      }
      else if(data[i] < 64)
      {
         data[i] = 0x00;
         output2 << "less than 64, set to 0x00." << endl;
      }
      else
      {
         // This is most likely pointless, but I didn't want to take a chance
         data[i] = 0x75;
         output2 << "neither greater nor less than 64? Set to 0x75." << endl;
      }

      output2 << endl;
   }

   output.write(&data[0],256);
}

Output (from message.txt):

Note: data[0-25] contain the correct values

…
Value data[19] = 19 less than 64, set to 0x00.
Value data[20] = 20 less than 64, set to 0x00.
Value data[21] = 21 less than 64, set to 0x00.
Value data[22] = 22 less than 64, set to 0x00.
Value data[23] = 23 less than 64, set to 0x00.
Value data[24] = 24 less than 64, set to 0x00.
Value data[25] = 25 less than 64, set to 0x00.
Value data[26] = 0 less than 64, set to 0x00.

  • 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-22T21:52:29+00:00Added an answer on May 22, 2026 at 9:52 pm

    If you look up what ascii code 25 is you’ll see it means end of medium so there’s a good chance that if you’re reading in ascii mode, any subsequent reads aren’t going to work.

    Try specifying that you’re using a binary file:

    sourcefile.open("Input.FILE", ios::binary);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.