I was recently working on a project for a class and was having a lot of problems with passing in command line arguments. I decided to test out with a really simple code I found online from geeksforgeeks to see if I could get any sort of command line stuff to work and it still is not working. It will not print any argv values and when I debug it, it says that argc is 1 despite me putting in 4 command line arguments. I have been trying to find answers to this online for hours and have no idea what is going on especially when using this really simple code. I attached the code I was testing below. It only prints out "You have entered 1 arguments:" I am relatively new to coding but very confused.
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
cout << "You have entered " << argc
<< " arguments:" << "\n";
for (int i = 0; i < argc; ++i)
cout << argv[i] << "\n";
return 0;
}
I was having the same problem - argc always 1. I tried Debug->myprojectname Debug Properties(at the bottom)->Debugging->Command Arguments and set my arguments there instead of Project->Properties->etc.
This worked for me. I am using VS2022 MFC and Win32(old x86 program). Hope this helps someone.