add ipi10

This commit is contained in:
2020-01-13 13:31:38 +01:00
parent 52cef9b878
commit 554b59e1f4
4 changed files with 206 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
// check if correct argument count
if (argc < 2) {
printf("Dateiname erwartet\n");
return 1;
}
// get filename from argument list
string filename = argv[1];
// open input file
ifstream fileIn;
fileIn.open(filename + ".txt");
// open output file
ofstream fileOut;
fileOut.open(filename + "-a.txt");
// check if we could open the files
if (!fileIn.good() || !fileOut.good()) {
// could not open files
cout << "Konnte Datei " + filename + ".txt nicht lesen" << endl;
return 1;
}
string input; // variable containing line
int lineNo = 1; // count lines
while(getline(fileIn, input)) { // while there is still a line left
// write out line with prepended line number to output file
fileOut << to_string(lineNo) + ": " + input << endl;
// increment line counter
lineNo += 1;
}
// close files
fileIn.close();
fileOut.close();
}