xmake run with arg
#include <iostream>
int main(int argc, char* argv[]) {
for (int i = 0; i < argc; ++i) {
std::cout << "Argument " << i << ": " << argv[i] << std::endl;
}
return 0;
}
Explanation:
#include \<iostream>: This line includes the iostream standard library, which provides basic input and output services for C++ programs.
int main(int argc, char* argv[]): This is the main function of the program, which takes two parameters: argc, an integer representing the number of arguments passed to the program, and argv, an array of strings representing the arguments themselves.
for (int i = 0; i < argc; ++i): This is a for loop that iterates over the arguments passed to the program. It initializes the loop counter i to 0, and the loop continues as long as i is less than argc.
std::cout << "Argument " << i << ": " << argv[i] << std::endl;: Within the loop, this line uses std::cout to output the index of the argument and the argument itself to the console.
return 0;: Finally, the main function returns 0, indicating successful execution of the program.