Passing more than one argument to argv in VS

I need to know how to pass more than one argument to argv in Visual Studio Community 2015. I have this code for printing the number arguments passed in, but it's only showing the one argument that's there by default:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "keep_window_open.h"

int main(int argc, char* argv[])
{
	using namespace std;
	cout << "There are " << argc << " arguments:\n";
	for (int count = 0; count < argc; ++count)
	{
		cout << count << " " << argv[count] << "\n";
	}
	keep_window_open();
	return 0;
}


What should I do?
Go to Project Properties. You can set the command line there. It's the same for all Visual Studio versions since 2002.
My problem that, for some reason, the programs I write always think there are no command-line arguments, even if I try to add some. Also, I tried to use the Visual Studio Command Prompt, but I don't know how to tell it where my keep_window_open.h header is, so I couldn't do it.
What? I'm not to familiar with Visual Studio however if you compiled your program with the IDE, then left the IDE and opened a Windows Command Prompt, changed to the directory where the executable program is located, then typed the name of the program and supplied the command prompts the program should run.

your_program_name "command line prompt 1" "Command Line Prompt 2" 3 5

Edit: Also if you are running from the Windows Command Prompt you don't even need to worry about keeping the command prompt open.
Last edited on
First of all, the Visual Studio Command Prompt and Windows Command Prompt won't even recognize the "clang++" command, even when I've set Visual Studio to use Clang as the compiler instead of the built-in compiler. I already know I have to change to the directory that I have the .cpp file in.
First of all, the Visual Studio Command Prompt and Windows Command Prompt won't even recognize the "clang++" command, even when I've set Visual Studio to use Clang as the compiler instead of the built-in compiler.


So then you're saying you can't compile the simple program in the original post?

I don't care if the Windows command prompt recognizes clang++ or not, if you can compile your program compile it. Then open the Windows command prompt and run your program, adding the desired command prompts.

I already know I have to change to the directory that I have the .cpp file in.

No you need to change to the directory where the executable is located, which may be different that where the .cpp file is located.

My problem that, for some reason, the programs I write always think there are no command-line arguments, even if I try to add some.

Make sure you hit the "Apply" button if you're making changes to project settings.
Guys, I already did ALL of that stuff. The code itself compiles in VS just fine, I just can't the command-line arguments to work. Running the code even with command-line arguments makes the program print that the filename is the only argument. And in programs where the command-line arguments show, sometimes it works as I want, but at other times it throws a bad write error and crashes.

Edit: I don't know what happened, but deleting the whole project and doing it from scratch again somehow helped.
Last edited on
Topic archived. No new replies allowed.