Merging 2 into a single alphabetized
May 11, 2014 at 7:19pm UTC
Please bare with me as I'm new to all this jazz. I'm sure I've made some simple "dumb" mistakes. I'm trying to merge input files
and
into one output
. I want them to be alphabetized in the output file, but I think I can figure that part out later. For now, I'm not sure what these errors are:
73 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'
77 cannot convert `std::string' to `char' in assignment
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
#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;
}
May 12, 2014 at 12:18am UTC
The errors are pretty straight forward.
On line 69 of your snippet, you are comparing an element of a string with a string (line[k] > nTemp).
On line 73, you're attempting to assign a string to an element of a string.
What are lines 63 - 74 supposed to do?
Topic archived. No new replies allowed.