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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:26:09+00:00 2026-05-12T07:26:09+00:00

Edit: I’m trying to convert a text file into bytes. I’m not sure if

  • 0

Edit: I’m trying to convert a text file into bytes. I’m not sure if the code is turning it into bytes or not. Here is the link to the header so you can see the as_bytes function.

link

#include "std_lib_facilities.h"

int main()
{
    cout << "Enter input file name.\n";
    string file;
    cin >> file;
    ifstream in(file.c_str(), ios::binary);

    int i;
    vector<int> bin;

    while(in.read(as_bytes(i), sizeof(int)))
        bin.push_back(i);

    ofstream out(file.c_str(), ios::out);

    for(int i = 0; i < bin.size(); ++i)
            out << bin[i];

    keep_window_open();
}

Note that now the out stream just outputs the contents of the vector. It doesn’t use the write function or the binary mode. This converts the file to a large line of numbers – is this what I’m looking for?

Here is an example of the second code’s file conversion:

that guy likes to eat lots of pie (not sure if this was exact text)

turns to

543518319544825700191924850016351970295432362115448292821701667182186922608417526375411952522351186935715718643976841768956006
  • 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-12T07:26:09+00:00Added an answer on May 12, 2026 at 7:26 am

    The reason your first method didn’t change the file is because all files are stored in the same way. The only “difference” between text files and binary files is that text files contain only bytes that can be shown as ASCII characters, while binary files* have a much more random variety and order of bytes. So you are reading bytes in as bytes and then outputting them as bytes again!

    *I’m including Unicode text files as binary, since they can have multiple bytes to denote one character point, depending on the character point and the encoding used.

    The second method is also fairly simple. You are reading in the bytes, as before, and storing them in integers (which are probably 4 bytes long). Then you are just printing out the integers as if they are integers, so you are seeing a string of numbers.

    As for why your first method cut off some of the bytes, you’re right in that it’s probably some bug in your code. I thought it was more important to explain what the ideas are in this case, rather than debug some test code.

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Lets say that succ(x)=x+1 pre(x)=x-1 Then, (in pseudocode) add(x,y) =… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer "The data needs to be transformed in the process from… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer This: y = (8 - x) % 7 This is… May 14, 2026 at 5:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.