generate by chatGPT
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
// The first argument is the program name, so we start from index 1
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--help") {
std::cout << "Usage: myprogram [options]\n"
<< "Options:\n"
<< " --help Display this help message\n"
<< " --input <file> Specify input file\n"
<< " --output <file> Specify output file\n";
return 0;
} else if (arg == "--input") {
if (i + 1 < argc) {
std::string input_file = argv[i + 1];
// Do something with input_file...
i++; // Skip the next argument, since we've already processed it
} else {
std::cerr << "--input option requires an argument.\n";
return 1;
}
} else if (arg == "--output") {
if (i + 1 < argc) {
std::string output_file = argv[i + 1];
// Do something with output_file...
i++; // Skip the next argument, since we've already processed it
} else {
std::cerr << "--output option requires an argument.\n";
return 1;
}
} else {
std::cerr << "Unknown option: " << arg << "\n";
return 1;
}
}
// Do something with the program's main logic...
return 0;
}