I am starting to learn c++ from java and because String in c++ is not data type stuff with switch is different to me.
This is my function in java
public static void fileCreationPo(Procesor pr,String name,String extension) {
String filePath = "C:\\Created Files\\";
String filePathFinal = filePath+name+extension;
try {
BufferedWriter bw= new BufferedWriter( new FileWriter(filePathFinal))
switch(extension)
{
case ".txt":
bw.write(pr.toStringN());
break;
case ".csv":
bw.write(pr.toString());
break;
default:
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
And I was wondering in c++ what would be the most efficient way to make "fileNameFinal" relative to extension typed in parameters and working "switch" without creating two parameters for almost the same thing if you can understand what I mean from java code
This is my failed attempt using enum
Also if you see anything the code could improve on I'll be more than glad to see it
enum swEE {
txt = 0,
csv,
sri
};
void fileCreationPr(Predmet pr, string nz, swEE se) {
string fileName("J:\\Personal\\ukolos\\IT\\vis\\pec.txt");
string fileNameFinal(fileName + ???? );
ofstream outFs(fileNameFinal, ofstream::out);
switch (se) {
case txt:
outFs << stringify(se) << pr.nazev << "\n" << pr.pocet << "\n" << pr.vaha;
break;
case csv:
outFs << pr.nazev << ";" << pr.pocet << ";" << pr.vaha;
break;
}
outFs.close();
};