I am making a linked list called docList, to assign a unique tag and a pointer to a ifstream file but it doesn't seem to work unless the file itself is a pointer.
I am parsing a much larger file into separate files to be added into docList and the implementation might to the cause of this too.
class docList {
public:
int docNumber;
ofstream*file;
docList* bottom;
docList();
void addDocument( ofstream);
};
There is more but I think this is all relevant code. I'd like to learn from critic as well.
int parseFile() // takes a file and splits into multiple files by paragraphs
{
bool open = true;
int fileNumber = 1;
string fileName;
string fileLine;
ifstream myFile;
cout << "Name of file: ";
cin >> fileName;
myFile.open(fileName);
if( !myFile.is_open() ) // Checks if file is found
{
cout << "File not found" << endl;
open = false;
}
else // File is available
{
ofstream fout;
while( !myFile.eof() )
{
getline( myFile, fileLine ); // Get single line from main file
stringstream sstream;
string fileIndex;
string outputFiles;
sstream <<fileNumber; // creating index for new files
sstream >> fileIndex;
outputFiles = "file" + fileIndex + ".txt";
fout.open(outputFiles); // writing to new files
L1:
{
fout << fileLine << '\n'; // Writes paragraph of main file into seperate files
getline( myFile, fileLine );
if( myFile.eof() ) goto L2;
}
if( fileLine!= "" ) goto L1;
L2:
fout << fileLine;
fileNumber++;
doc.addDocument( fout );
fout.close();
}
}
myFile.close();
return fileNumber;
}