I want to input a bunch of image files from the same folder and apply them the same operation inside a for-loop. I defined main as int main(int argc, char** argv) have this for-loop:
for(int i=1; i < argc; ++i)
{
// do something here
}
In Eclipse CDT (Neon), under Run configurations > Arguments, I'm entering the paths of images that I want to process. It works when I explicitly give a list of images like img1.jpg img2.jpg ... however it doesn't work when I give try to run it on all the image files with a certain extension such as dataset/*.jpg.
Is there a workaround for this? Thanks.
Is there a workaround for this?
The two most obvious ones that come to mind are:
Run the program from a terminal instead of from inside Eclipse.
Modify the program to take just the directory name as the argument, and have it iterate over the files in the directory.
Related
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.
As we know the Query String in web. It's key/value go with the website URL ex: abc.com?myName=stack
For example in PHP, if we want get value of the myName, just do this $_GET['myName']
So, in C++, how can I get it?
in C# I pass an parametter to an *.exe file ( this exe file is C++ code ).
In C++ code, how to get this parametter value .
Build a console application with just the following code:
#include <iostream>
int main(int argc, char** argv)
{
for(int i = 1; i != argc; ++i )
{
std::cout << argv[i] << std::endl;
}
}
Assuming the name of the .exe is mytest.exe, execute it with some arguments, such as:
mytest.exe Hello there.
You should get the following output:
Hello
there.
Hope the simple example makes it clear as to how to process command line arguments in C++.
Have no idea about your situation, but surely you will have realize what parameters do you really need?
If you just need arguments from the command line, simple use the char** argv variable. In complicated cases you can use GNU getopt or even Boost::Program_options (the last is cross-platform);
If you are trying to access environmental variables, use standard getenv functions.
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
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.
how can I run two main Visual Studio (Visual C ++)..
I would like to have a main that represents the server and a main that is
the client and run them running on two different consoles.
how can I do?
It is possible to create two separate projects within a single Visual Studio solution. Each one can be an independent console application with its own main entrypoint. However, the simplest way to do that if you are wanting to debug both projects at the same time is to open two separate instances of Visual Studio, one with the client solution and one with the server.
Create two functions:
int server_main( int argc, char* argv[] );
int client_main( int argc, char* argv[] );
in the actual
int main( int argc, char* argv[] )
check for a command line argument ( --server or --client ) and then depending on which one is present, delegate to server_main or client_main.
When it comes to debugging, do what they've already suggested which is run two different instances of VS.
Everybody else is right in pointing out that there can be only one "main", but I think this answers what you actually wanted to ask.
You can't have two main functions. Either have separate builds with ifdef guards or a command line argument.
You have to create two separate programs. Each program will have its separate main() function.
Create a library with the shared code (assuming that's what you're after here) and create two separate binaries, one for the server and one for the client.