jeudi 5 février 2015

C++ Sorting .txt files using a template

I am trying to write a program that takes 3 input .txt files, uses a template to sort the files, and write the sorted data to 3 output files. The 3 input .txt files I am trying to sort are IntFile.txt, FloatFile.txt, and QUOTES.txt. The type of data stored in the files is integers, doubles, and strings, respectively. Right now I am trying to just get the IntFile.txt to sort and am having trouble reading the .txt file and saving it to an array to send to my template to sort. I cannot figure out a way to stop the for loop once it reads the last data from the file. The program I have written thus far is



`#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include "sorting.h"
using namespace std;

int main()
{

ifstream inNumbers("IntFile.txt");
ifstream inFloaters("FloatFile.txt");
ifstream inWords("QUOTES.txt");
ofstream outNumbers("SortedInt.txt");
ofstream outFloaters("SortedFloat.txt");
ofstream outWords("SortedQuotes.txt");

int i, length = 0;
int data[100];

if (!inNumbers)
{
cerr << "IntFile.txt file could not be opened" << endl;
exit(1);
}

if (!inFloaters)
{
cerr << "FloatFile.txt file could not be opened" << endl;
exit(1);
}

if (!inWords)
{
cerr << "QUOTES.txt file could not be opened" << endl;
exit(1);
}

for (i = 0; data[i] ; ++i)
{
inNumbers >> data[i];
length += 1;
}

sorting(data[100], length);

}`

Aucun commentaire:

Enregistrer un commentaire