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

  • Home
  • SEARCH
  • 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 6927187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:00:58+00:00 2026-05-27T11:00:58+00:00

Im working on a two part program that uses an encoder do encode a

  • 0

Im working on a two part program that uses an encoder do encode a text file then a decoder to decode the text file. However i cannot get my decoder to read the whole text file it just reads the first line. How do i fix this, ive played around with the loops but it is not helping me.

#include <fstream> 
#include <iostream> 
#include <string> 
using namespace std; 

int main() 
{ 
    ifstream fin;
    ofstream fout;
    string lineFromFile; 
    fin.open("secret.txt");
    if (!fin.good()) throw "I/O error";
    fout.open("secret.txt", ios::app); 
    if (!fout.good()) throw "I/O error"; 

    while (fin.good())
    {
        getline(fin, lineFromFile); 
        for (int i = 0; i < lineFromFile.length(); i++) // for each char in the string...
            lineFromFile[i]--; // bump the ASCII code by 1
        fout << lineFromFile << endl;     
    }//while

    fin.close();
    fout.close();
    return 0;
}
  • 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-27T11:00:59+00:00Added an answer on May 27, 2026 at 11:00 am

    You are closing the stream in the first iteration (i.e., after reading the first line). Then you open the output stream to write the first line. Only then do you reach the end of the while-loop, at which time fin.good() cannot be true anymore since you closed fin.

    The loop should contain only the reading and writing. Opening done before the loop, closing done after.

    Additional suggestion: Use proper indenting, it helps understanding the control flow.

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

Sidebar

Related Questions

I'm working with two-dimensional array-values that should be inserted into a ArrayList. But this
A part of an application I'm working on is a simple pthread-based server that
For the project I'm working on, we have a desktop program that contacts an
I am working on a program in C as a part of Homework in
Recently I've been working on a C++ prime generator that uses the Sieve of
I am working on part of my program where I am deleting entry by
As part of my work, I am working with very large text files and,
Okay so right now I'm working on a program that has a whole bunch
I'm working on a program, and I'm trying to display the assembly FILE version
I'm currently working on two projects simultaneously: My main project (built with maven) A

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.