Skip to content

Instantly share code, notes, and snippets.

@HotoRas
Created February 1, 2024 11:08
Show Gist options
  • Save HotoRas/b4fa47dffcee052b1a6f2189d8cb065c to your computer and use it in GitHub Desktop.
Save HotoRas/b4fa47dffcee052b1a6f2189d8cb065c to your computer and use it in GitHub Desktop.
Argument logger
#include <iostream>
#include <fstream>
int main(int argc, char* argv[]) {
std::string file = "args.log"; // log file path
std::ofstream stream(file.data()); // out file stream: fstream as write mode
if (stream.is_open()) {
for (int i = 0; i < argc; i++) // arguments count at argc, so log it all with file name in argv[0]
stream << argv[i] << std::endl; // write args into file
stream.close();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment