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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:36:32+00:00 2026-05-27T23:36:32+00:00

When we create a text file with this text ali ata bak, and we

  • 0

When we create a text file with this text “ali ata bak”, and we use this file as input for the program. The code is running normally. But when we enter “1111111111111111111111” this text in the textfile, Code isnt running expected. So What is the problem?

#include <QtCore/QCoreApplication>
#include <QBitArray>
#include <QByteRef>
#include <QFile>
#include <iostream>
#include <stdlib.h>
#include <QTextStream>

// Buffer Size #num of KB's
#define BUFFER_SIZE_KB 1

// Do not change !!
#define BUFFER_SIZE_BYTE BUFFER_SIZE_KB*1024
#define BUFFER_SIZE_BIT  BUFFER_SIZE_BYTE*8

using namespace std;


QBitArray bytesToBits(QByteArray bytes) {
    QBitArray bits(bytes.count()*8);
    // Convert from QByteArray to QBitArray
    for(int i=0; i<bytes.count(); ++i)
        for(int b=0; b<8; ++b)
            bits.setBit(i*8+b, bytes.at(i)&(1<<b));
    return bits;
}


QByteArray bitsToBytes(QBitArray bits) {
    QByteArray bytes;
    bytes.resize(bits.count()/8);
    // Convert from QBitArray to QByteArray
    for(int b=0; b<bits.count(); ++b)
        bytes[b/8] = ( bytes.at(b/8) | ((bits[b]?1:0)<<(b%8)));
    return bytes;
}


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString inFilename;
    QString outFilename;
    QTextStream qtin(stdin);


    cout << "Filename : ";
    qtin >> inFilename;
    outFilename.append("_");
    outFilename.append(inFilename);

    QFile infile(inFilename);
    if (!infile.open(QIODevice::ReadOnly)) {
        cout << "\nFile cant opened\n";
        system("pause");
        return 1;
    }

    QFile outfile(outFilename);
    if (!outfile.open(QIODevice::WriteOnly)) {
        cout << "\nFile cant opened\n";
        system("pause");
        return 2;
    }

    QByteArray bytes, bytes2;
    QBitArray bits;


    while ((bytes = infile.read(BUFFER_SIZE_BYTE)) >0 ) {

        bits = bytesToBits(bytes);
        bytes2 = bitsToBytes(bits);// PROBLEM IS HERE
        outfile.write(bytes2);

    }

    outfile.close();
    infile.close();
    cout << "Finished\n";
    return a.exec();
}
  • 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-27T23:36:33+00:00Added an answer on May 27, 2026 at 11:36 pm

    Initialization problem.

    QByteArray bitsToBytes(QBitArray bits) {
        QByteArray bytes;
        bytes.resize(bits.count()/8+1);
        bytes.fill(0);
        // Convert from QBitArray to QByteArray
        for(int b=0; b<bits.count(); ++b)
            bytes[b/8] = ( bytes.at(b/8) | ((bits[b]?1:0)<<(b%8)));
        return bytes;
    }
    

    this produces the right answer

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

Sidebar

Related Questions

I'm trying to create a program that takes a text file of c++ code
i tried to read text file in xcode but this EXC_BAD_ACCESS message showed up
There's this program, pdftotext, that can convert a pdf file to a text file.
I want to create a Text file in my code behind file in my
I am trying to create a text file using VB.Net with UTF8 encoding, without
I'm looking for a way to (hopefully) create a text file which lists all
Create a flat text file in c++ around 50 - 100 MB with the
I need to create an ANSI text file from an Access recordset that outputs
I want to be able to create a temporary text File in Java to
How to append text to a text file in C++? And create a new

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.