Just that. You noticed how it didn't work, just now? It claimed that you didn't give any arguments, when in fact you gave two. What do you think that if(argc==2) does, and why isn't it what you want?
Printable View
Alright if argv[0] = appName and argv[1] = -t and argv[2] = input.....then what the heck does argc stand for? I thought it was a count of the number of arguments the user entered? If so then yes I did it incorrectly. When I set it to if argc==0 then it came up with this error when I ran the program :"Segmentation fault".
I thought I made it clear in my second response. argc is the number of arguments in argv. Like any other array, you can access up to argv[argc-1].
Post your whole code. I don't see why a segfault would have come up.
That is the whole code.
I hadn't used this in a while... but I used to like to use this construct for C++ programs when I was first using C++.
CPPMain.h
Example:Code:#ifndef MAIN__INCLUDE_ONCE_EVER__
#define MAIN__INCLUDE_ONCE_EVER__ 1
#include <vector>
#include <string>
typedef std::vector<std::string> Argv;
int Main(const Argv &);
int main(int argc, char **argv)
{
Argv v;
for(register int i = 0;i < argc;++i)
v.push_back(argv[i]);
return Main(v);
}
#endif
I dunno... It has its pros and cons but it may help you in your project.Code:#include "CPPMain.h"
int Main(const Argv &argv)
{
// Your code goes here...
return 0;
}
I probably could have done a quick sample of how to use the Main() function...
Example:
Code:int Main(const Argv &argv)
{
for(int i = 0; i < argv.size(); ++i)
if(argv[i] == "-t")
{
// whatever
} else if(argv[i] == "-t")
{
// whatever
}
return 0;
}
Sorry but the example at the bottom of this link was what I ended up understanding and using. Although I broke it up into a separate class to parse out the arguments for me.
http://www.phon.ucl.ac.uk/courses/sp...c/lesson11.htm