C++ VS2010 not using my Debug command line args - c++

In VS2010 I set command line arguments in the project settings->Debugging->Command line arguments:
-d 48000 1 -raw test1.opus test1_decoded.raw
However, when I debug the project and have a look at the argv[] in
int main(int argc, char *argv[])
{
}
... I can see that these command line arguments are missing.
The command line argument argv instead has only the path to the exe that is just being debugged. I see that if I move the mouse over the argv.
Does anybody have an idea what I might have done wrong?
Thank you for the help.

However, when I debug the project and have a look at the argv[]...
Per your description and code, I'm assuming that you are hovering your mouse over argv or looking at it in the watch window. argv is a pointer to pointer to char. The debugger does not know how many elements it contains. It will show you the first element i.e.,*argv`), but no more because there is simply no safe, standard way of doing so.
Your command line arguments are there, but the debugger cannot figure out how many elements to display in the UI. Look at the value of argc; that should match your number of arguments +1 for the path to your executable.

Related

.exe does not run with more than one instance of "../" in the path

Issue
I have a Release-compiled MSVC C++17 "server" application. I usually make a child process from the client application to run a local server, so I use a relative directory path for the command line to execute as the child process. I am emulating that call here by typing in the relative path manually in powershell from where the client application executable runs.
It seems running run_Server.exe works with a command line like:
(Case 1)
PS C:\Users\me\Documents\MyProjectRelease1.0\Client_App_Folder> ../Server_App_Folder/run_Server.exe -help
(Proceeds to print out help)
But not with a command line like:
(Case 2)
PS C:\Users\me\Documents\MyProjectRelease1.0\Client_App_Folder\Client_App_Subfolder> ../../Server_App_Folder/run_Server.exe -help
(Waits a second then exits the program without any output)
Note: Client_App_Subfolder has an identical name as Client_App_Folder due to unimportant reasons.
Why is this happening? I may be mistaken, but I thought this did not happen under the exact same circumstances previously. I'm not finding much in the way of documentation about this phenomenon yet. I think this might have something to do with the up-directory ..\s in the command. Slash direction seems to not alter the results in this case in powershell.
Attempted Troubleshooting
Here's the first portion of main.cpp:
// Other #includes above.
#include <filesystem>
#include <iostream>
int main(int argc, char* argv[])
{
std::filesystem::path cwd = std::filesystem::current_path() / "filename.txt";
std::ofstream file(cwd.string());
file.close();
// ...proceed to parse command line arguments, etc.
}
This code results in outputting filename.txt in the MyProject\Client_App_Folder directory for the first case, but nothing for the second case.

VideoCapture with " int main(int argc, char **argv) "

I'm trying to use VideoCapture. a part of my code is below.
when I run my code, I got this :
Error! Insufficient parameters provided.
How can I use my video with this code. I want to open a stream with VLC.
Or if is there any other way, I'd like to use.
I searched that argv[1] is will be my video file. But I don't know how to show my file and how to define my file to this code.
To help future users, I'd make some changes:
Was:
LOG_DEBUG("Error! Insufficient parameters provided.");
Is:
std::string program(argv[0]);
LOG_DEBUG("Error! Insufficient parameters provided.");
LOG_DEBUG("Please provide a command line argument.");
LOG_DEBUG("Example: " << program << " VIDEO_FILE_NAME");
Explanation:
On the command line, when the program is invoked, the arguments from the command line are copied in the array of strings held by argv. argv[0] is the first argument and it is the filename of the program itself. Put another way, argv[i] for 0 <= i < argc are populated in the array of strings argv from the command line. If you renamed the program executable file, argv[0] would be different the next time you ran the program.
The array argv is indexed from 0 to argc-1. When main is invoked this array of strings and argc are set. It's up to the software to decide what to do. In this case your application tests argc and finds that if no argument is provided (ie., argc < 2) then the one user argument provided by the user is not present, report the error and return.
Incidentally, there's yet another form of main you can use:
int main(int argc, char** argv, char** envp)
argc = number of arguments.
argv = array of argument strings
envp = array of environment variable name=value pairs
So beyond simple command line argument passing, one could choose to write the main function to grab the environment variables (not shell variables) and decide nuanced action based on that. Options abound.
But for the time being, your code would be helpful if it reported why there is an error and the suggestions provided seem to do that.
Good luck.

Kdevelop execute project with parameters

I am new to Kdevelop and I am trying for 2 hours to run a project based on input parameters in C++ style.
The code is here:
int main(int argc, char** argv)
{
std::string s = args[1]
std::cout<<s<<std::endl;
}
I am trying to add the parameter, but it is crashing and saying
Process Error - Kdevelop
A shell meta character was included in the atguments for file launch ...
Can anyone tell me what is it about? Andhow can I fix it, or where shall I add the execution parameters?
I have placed them in the Launch -> Configuration Launches -> Behaviour -> Arguments see below
Please help
The arguments must be between quotes:
"/your folder and path/Your file"
or
"enter your parameter here"
instead of
just the parameter

Using Command Line Arguments To Input Parameters

So I have a Windows Studio VS File named RectArea that contains the code to a function to find the area of a rectangle. In another Windows Studio VS file named main1, I have my main function like this:
int main(int argc, char *argv[])
{
return 0;
}
How do I use command line arguments to be able to print the area of the rectangle in the main file as soon as i compile it?
I read so much stuff about it online. I just still don't understand what I put for the executable and the stuff after it.
My function for the rectangle's area is in the RectArea file. Do I type in C://RectArea?
It's under a lot more folders though.
Ah, you're confused on how to pass the arguments to the program, not how to interpret them. Those arguments are not command line arguments passed to the Visual Studio build process; they're arguments that can be changed each time you run the program.
An executable written with an entry point like that can't be run properly via double-click like all the others you've written; you have to open cmd.exe and run the program from there, typing the arguments after the program name separated by a space.

When opening a program in a Unix terminal, is there a way to have the program name and its input on the same line?

I have a C++ program that accepts three inputs: an integer for width, an integer for height, and a filename. Right now, I compile, and run the program like this (assuming I named it prog):
>prog
// hit enter
>128 128 output.ppm
This results in a successful output, but the program description says the proper command-line syntax is:
>prog w h filename
That's all it says. Does this imply that my program should be able to start on the same line? Perhaps it implicitly means you hit enter after typing the program name, but if not, is there a way to actually do this?
Your program needs to parse command line parameters. Looking at the specification, the expected workflow is
>prog 128 128 output.ppm
//hit enter after the parameters
Look here to learn more.
You're approaching the problem incorrectly. You are taking your input via std::cin after your program has been started. Your program specification states that the input should be given as part of the command. Consider a command like ls -l - the -l is part of the command and is passed to the program to parse and act upon.
You need to allow a command like prog 128 128 output.ppm to be run, so the user would type that and then press enter to run the program. How do you get access to the command line arguments within your C++ program? Well, that's what the argc and argv parameters of the main function are for. Your main function should look like this:
int main(int argc, char* argv[]) { ... }
The argc argument gives you the number of arguments passed in the command line (it will be 4, in the example given) which is also the size of the argv array. Each element is an argument from the command. For example, argv[0] will be "prog", argv[1] will be "128", and so on. You need to parse these values and, depending on their values, change the functionality of your program.
You can pass command via the argument in the main function:
int main(int argc, char *argv[]) {
}
argc is the number of arguments and argv is an array of arguments.