Program can't locate .txt file

Started by
11 comments, last by theBegger 9 years, 11 months ago

I personally use two sites:

http://en.cppreference.com/w/

http://www.cplusplus.com/reference/

As for the reloading the output, i'm guessing you have the output file open in your IDE or another editor, each time you run the program, the file is modified, so you get asked if you want to reload it.

devstropo.blogspot.com - Random stuff about my gamedev hobby

Advertisement

I got it to work, but then I started writing again sleep.png. I can't figure out why I'm getting this error. It's calling for a declaration where I thought I had already declared things....

107 expected declaration before '}' token

[Build Error] [Merger.1.o] Error 1

The code is mostly the same, except I hadn't ended the while loop in the main function. So when I added a braket to close that loop, I got this pretty little error.


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

#define theAdopted "The Adopted.txt"            //His family
#define theOriginals "The Originals.txt"        //Her family
#define theBigPicture "The Big Picture.txt"     //Our family

//Function Prototypes

class KeepRunning {                            //Prototype needed to keep console from closing.
  public:
    ~KeepRunning() {
      cin.get();}};

//Copies text
int copyLine(ifstream&, ifstream&, ofstream&);

int main()                                                                  
{   
    KeepRunning kr;  
     
    ifstream hisFamily("The Adopted.txt");
    ifstream herFamily("The Originals.txt");
    ofstream ourFamily("The Big Picture.txt");
    
    int SIZE1 = 200, SIZE2 = 200;  
    int insA[SIZE1]; 
    int insB[SIZE2];
    int outs[SIZE1 + SIZE2];
    int lineCount;
    int index1 = 0; 
    int index2 = 0;
    int A = 0;
    int B = 0;
    
    //Retreive his family's grades.
    hisFamily;
    if(hisFamily.fail())
    {
        cerr << "ERROR: Cannot open " << theAdopted << ". \n";
        return EXIT_FAILURE;
    } 
    //Retreive her family's grades.
    herFamily;
    if(herFamily.fail())
    {
        cerr << "ERROR: Cannot open " << theOriginals << ". \n";
        return EXIT_FAILURE;
    }
    //Call theBigPicture.
    ourFamily;
    if(ourFamily.fail())
    {
        cerr << "ERROR: Cannot open " << theBigPicture << ". \n";
        return EXIT_FAILURE;
    }        
    //Copy data hisFamily to ourFamily.
    string line;
    lineCount = 0;
    getline(hisFamily, line);
    while(line.length() != 0)
    {
        lineCount++;
        ourFamily << line << endl;
        getline(hisFamily,line); 
    } 
    
    cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
    //Close files.
    hisFamily.close();
    herFamily.close();
    ourFamily.close();
    return 0;
}  
int copyLine
    (ifstream& hisFamily,
     ifstream& herFamily,
     ofstream& ourFamily)
     {
         const char NWLN = '\n';
         char nextCh;
         int charCount = 0;
         
         //Merge
         hisFamily.get(nextCh);
         while ((nextCh != NWLN) && !hisFamily.eof())
         {
             ourFamily.put(nextCh);
             charCount++;
             hisFamily.ignore(nextCh);
             hisFamily.get (nextCh);
         }
         if(!hisFamily.eof())
         {
             ourFamily.put(NWLN);
             charCount++;
         }
         return charCount;
     }
}

Wow disregard that....I had an extra bracket unsure.png

This topic is closed to new replies.

Advertisement