Trouble Merging

I'm trying to merge two files, The Adpoted.txt, and The Originals.txt, into one file, The Big Picture.txt. I'm compiling and getting an insane amount of errors, and am not even sure where to start with them :(. I'm getting errors for lines that don't exist. I suppose I should start with those that do!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <fstream>
#include <cstdlib>
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

int merge(ifstream&, ifstream&, ofstream&);

int main ()
{
    int familialGrades = 0;                     //Grades in life.
    hisFamily ins;                              //IN: His family's life grades.
    herFamily ins;                              //IN: Her family's life grades.
    ourFamily outs;                             //OUT: Our family's are one family, and they have grades.
    
    //Retreive his family's grades.
    ins.open(theAdopted);
    if(ins.fail())
    {
        cout << "ERROR: Cannot open" << theAdopted << ". \n";
        return EXIT_FAILURE;
    }
    //Retreive her family's grades.
    ins.open(theOriginals);
    if(ins.fail())
    {
        cerr << "ERROR: Cannot open" << theOriginals << ". \n";
        return EXIT_FAILURE;
    }
    //Write both retreived files to theBigPicture.
    outs.open(theBigPicture);
    if(ins.fail())
    {
        cerr << "ERROR: Cannot open" << theBigPicture << ". \n";
        return EXIT_FAILURE;
    }        
    //Merge families.
    string line;
    lineCount = 0;
    eds.ignore(100, '\n');
    getline(eds, line);
    while(line.length() != 0)
    {
        lineCount++;
        outs << line << endl;
        getlin(name, line);
    }
    //Alphabetize
    string nTemp;
    for (int j = 1;j < 100; j++)
    {
    nTemp = name[j];
    int k;
    
    for (k = j-1; k >= 0 && name[k] > nTemp; k--)
    {
        name[k+1] = name[k];    
    }
    name[k+1] = nTemp;
    }
    //Display completion message.
    cout << "Merge complete.\n";
    //Close files.
    ins.close();
    outs.close();
    return 0;
}
 

What type is 'hisFamily', 'herFamily', etc? Presumably std::ifstream or std::ofstream, from how they are being used. Why are you trying to make multiple variables with the same name ('ins') ?

You haven't declared a type for 'lineCount' (presumably you want unsigned int), you misspelt getline on line 49, you have no streams called 'eds' or 'name', but then you start trying to use this still nonexistant 'name' as an array...

On a logical note, if you are returning 'EXIT_FAILURE' on fail, you may as well keep it neat and return 'EXIT_SUCESS' on successful finish (even though that should turn into '0').

I would say you have a few problems. I'm probably still missing some more as well...
Last edited on
Yeah....sorry about that. I probably should have posted on the Beginners page. That was pretty ugly. I've edited, and now I have two errors.

New code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
using namespace std;

#define inFileA "The Adopted.txt"            //His family
#define inFileB "The Originals.txt"          //Her family
#define outFile "The Big Picture.txt"        //Our family


//Function to alphabetize
float alphabetize(ifstream&, ofstream&);
//int merge(ifstream&, ifstream&, ofstream&);

int main ()
{
    int familialGrades = 0;                    //Grades in life.
    int lineCount = 0;                         //Asign variable to count lines read.
    ifstream insA;                             //IN: His family's life grades.
    ifstream insB;                             //IN: Her family's life grades.      
    ofstream outs;                             //OUT: Our family's are one family, and they have grades.
    int j = 0;
    
    //Retreive his family's grades.
    insA.open(inFileA);
    if(insA.fail())
    {
        cerr << "ERROR: Cannot open" << inFileA << ". \n";
        return EXIT_FAILURE;
    }
    //Retreive her family's grades.
    insB.open(inFileB);
    if(insB.fail())
    {
        cerr << "ERROR: Cannot open" << inFileB << ". \n";
        return EXIT_FAILURE;
    }
    //Call theBigPicture.
    outs.open(outFile);
    if(outs.fail())
    {
        cerr << "ERROR: Cannot open" << outFile << ". \n";
        return EXIT_FAILURE;
    }        
    //Process info
    vector <float> alphabetize();
    //Copy data
    string line;
    lineCount = 0;
    insA.ignore(100, '\n');
    insB.ignore(100, '\n');
    getline(insA, line);
    getline(insB, line);
    while(line.length() != 0)
    {
        lineCount++;
        outs << line << endl;
        getline(insA, line);
        getline(insB, line);
    }
    //Alphabetize
    string nTemp;
    for (int j = 1;j < 100; j++)
    {
    nTemp = line[j];
    int k;
    
    for (k = j-1; k >= 0 && line[k] > nTemp; k--)
    {
        line[k+1] = line[k];    
    }
    line[k+1] = nTemp;
    }
    //Display completion message.
    cout << "Merge complete.\n";
    //Close files.
    insA.close();
    insB.close();
    outs.close();
    return 0;
}

    


Errors:

74 no match for 'operator>' in '(&line)->std::basic_string<_CharT, _Traits, _Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((unsigned int)k)) > nTemp'
78 cannot convert `std::string' to `char' in assignment
Topic archived. No new replies allowed.