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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:51:31+00:00 2026-05-11T07:51:31+00:00

This is in reference to another question I asked, though it is its own

  • 0

This is in reference to another question I asked, though it is its own question entirely.

when I compile I get two errors:

1>.\asst4.cpp(73) : error C2065: ‘outfile’ : undeclared identifier

1>.\asst4.cpp(73) : error C2228: left of ‘.close’ must have class/struct/union

I’m slightly confused as to what I’ve done incorrectly here? Any reccomendations or ideas? (The actual outfile is near the top of the code.

Here is the full code:

#include<iostream> #include<fstream>  //used for reading/writing to files. #include<string>    //needed for the filename. #include<stdio.h>   //for goto statement  using namespace std;  int main() {     string start;     char choice;     char letter;     int x;     int y;     int z;     string filename;     int garbage = rand()%('!' - '~' + 1 );     cout << 'Would you like to encrypt or decrypt a file? Please type enc, dec, or stop (case sensitive): ' ;     cin >> start;     while(start == 'enc')     {         x = 1;         y = 1;         cout << 'How many garbage characters would you like between each correct character?: ' ;         cin >> z;         cout << endl << 'Please insert the name of the document you wish to encrypt, make sure you enter the name, and the file type (ie: filename.txt): ' ;         cin >> filename;         ifstream infile(filename.c_str());         while(!infile.eof())         {             ofstream outfile('encrypted.txt', ios::out);             infile.get(letter);              if (x == y)                          {                 outfile << garbage;                 x++;                          }             else             {                 if((x - y) == z)                             {                     outfile << letter;                               y = x;                                   }                 else                                         {                                                outfile << garbage;                     x++;                 }             }         }         cout << endl << 'Encryption complete...please return to directory of program, a new file named encrypted.txt will be there.' << endl;         infile.close();         outfile.close();         cout << 'Do you wish to try again? Please press y then enter if yes (case sensitive).';         cin >> choice;         if(choice == 'y')         {             start = 'enc';         }         else         {             cout << endl << 'Do you wish to decrypt a file? Please press y then enter if yes (case sensitive).';             if(choice = 'y')             {                 start == 'dec';             }             else             {                 start == 'no';             }         }     }     while(start == 'dec')     {        //lets user choose whether to do another document or not.       //used to track each character in the document.         x = 1;    //first counter for tracking correct letter.         y = 1;    //second counter (1 is used instead of 0 for ease of reading, 1 being the 'first character').               //third counter (used as a check to see if the first two counters are equal).         //allows for user to input the filename they wish to use.         cout << 'Please make sure the document is in the same file as the program, thank you!' << endl << 'Please input document name: ' ;         cin >> filename; //getline(cin, filename);           cout << endl;         cout << ''Every nth character is good', what number is n?: ';         cin >> z;   //user inputs the number at which the character is good. IE: every 5th character is good, they would input 5.         cout << endl;         z = z - 1;  //by subtracting 1, you now have the number of characters you will be skipping, the one after those is the letter you want.         ifstream infile(filename.c_str()); //gets the filename provided, see below for incorrect input.         if(infile.is_open()) //checks to see if the file is opened.         {             while(!infile.eof())    //continues looping until the end of the file.             {                        infile.get(letter);  //gets the letters in the order that that they are in the file.                     if (x == y)          //checks to see if the counters match...                     {                         x++;             //...if they do, adds 1 to the x counter.                     }                     else                     {                         if((x - y) == z)            //for every nth character that is good, x - y = nth - 1.                         {                             cout << letter;         //...if they don't, that means that character is one you want, so it prints that character.                             y = x;                  //sets both counters equal to restart the process of counting.                         }                         else                        //only used when more than every other letter is garbage, continues adding 1 to the first                         {                           //counter until the first and second counters are equal.                             x++;                         }                     }             }             cout << endl << 'Decryption complete...please return to directory of program, a new file named encrypted.txt will be there.' << endl;             infile.close();             cout << 'Do you wish to try again? Please press y then enter if yes (case sensitive).';             cin >> choice;             if(choice == 'y')             {                 start == 'dec';             }             else                 {                 cout << endl << 'Do you wish to encrypt a file? Please press y then enter if yes (case sensitive).';                 if(choice == 'y')                 {                     start == 'enc';                 }                 else                 {                     start == 'no';                 }             }         }         else  //this prints out and program is skipped in case an incorrect file name is used.         {             cout << 'Unable to open file, please make sure the filename is correct and that you typed in the extension' << endl;             cout << 'IE:' << '     filename.txt' << endl;             cout << 'You input: ' << filename << endl;             cout << 'Do you wish to try again? Please press y then enter if yes (case senstive).' ;             cin >> choice;             if(choice == 'y')             {                 start == 'dec';             }             else             {                 start == 'no';             }         }         getchar();  //because I use visual C++ express.     } } 

Thanks ahead of time! Jeff

  • 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. 2026-05-11T07:51:32+00:00Added an answer on May 11, 2026 at 7:51 am

    Scoping issue. You are declaring outfile within your while loop, yet are trying to access it outside of said while loop.

    Move ofstream outfile('encrypted.txt', ios::out); to the line right after your ifstream infile(filename.c_str()); which is before your while(!infile.eof()).

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

Sidebar

Ask A Question

Stats

  • Questions 229k
  • Answers 229k
  • 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 I prefer to keep my models in models.py and managers… May 13, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Depends whether you mean mock or mock™… Given you are… May 13, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Check this out: WPF Toolkit adds Ribbon Control to .NET… May 13, 2026 at 1:48 am

Related Questions

I feel like this one has been asked before, but I'm unable to find
I have a Java background so I’m used to having Maven handle all problem
In this question , I asked about using queue's and threads in C#. I
I've actually asked about this already in this post although we've gone back to

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.