Skip to content

Commit

Permalink
update outputFileStream
Browse files Browse the repository at this point in the history
  • Loading branch information
a1henu committed May 1, 2024
1 parent 6de6742 commit 5561967
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ std::unordered_map<std::string, CitationPtr> loadCitations(const std::string& fi

int main(int argc, char** argv) {
std::unordered_map<std::string, CitationPtr> citations;
std::string citationFile, inputFile;
std::ofstream outputFile;
std::string citationFile, inputFile, outputFile;
std::ofstream outputFileStream;
std::ostream* output;

if (argc == 4) {
Expand All @@ -63,12 +63,7 @@ int main(int argc, char** argv) {
}
citationFile = argv[2];
citations = loadCitations(citationFile);
outputFile.open(argv[4]);
if (!outputFile) {
throw CitationError("Failed to open output file\n");
std::exit(1);
}
output = &outputFile;
outputFile = argv[4];
inputFile = argv[5];

} else {
Expand All @@ -84,6 +79,11 @@ int main(int argc, char** argv) {
// auto input = readFromFile(argv[3]);
// ...

if (argc == 6) {
outputFileStream.open(outputFile);
output = &outputFileStream;
}

// print the paragraph first
std::set<std::string> citationIDs;
std::ifstream inputFileStream{inputFile};
Expand All @@ -105,7 +105,5 @@ int main(int argc, char** argv) {
for (auto id : citationIDs) {
*output << citations[id]->toString() << std::endl;
}
if (argc == 6) {
outputFile.close();
}

}

0 comments on commit 5561967

Please sign in to comment.