ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
do {
next_option = getopt_long (argc,argv,short_options,long_options,NULL);
switch (next_option) {
case 'h':
print_usage(cout, 0);
case 'o':
output_filename = optarg;
break;
case 'v':
verbose = 1;
break;
case '?':
print_usage (cerr, 1);
case -1:
break;
default:
abort();
}
} while (next_option != -1);
if (verbose) {
for (int i = optind; i < argc; i++)
cout << "Argument : " << argv[i] << endl;
}
return 0;
}
I got a series of error messages , which I shall post here.
They are...
$ g++ -g getopt_long.cpp -Wall
getopt_long.cpp: In function `int main(int, char**)':
getopt_long.cpp:29: invalid conversion from `const char*' to `int'
getopt_long.cpp:29: invalid conversion from `const char*' to `int'
getopt_long.cpp:29: invalid conversion from `const char*' to `int'
Compilation exited abnormally with code 1 at Thu Aug 28 09:32:27
I don't know what are the messages.
I tried the same code with c, and it compiled with a series of warnings. I got the code form Advanced Linux Programming, and I want to use the getopt in a C++ program of mine.
if you want a character then enclose it in ' not in ", double quotes produce null terminated strings. also please use code tags, makes the code a lot easier to read
Thank you very very much, kev82. I did not notice it and was very frustrated with this error.
Ok, what do you mean by code tags?
I use emacs, and it automatically formats the code, and when I cut and pasted it into konqueror, the format was gone. Is this what you were referring to?
i meant on the forum, you can use different tags to keep the code formatted correctly, instead of losing your formatting, makes it much easier for everyone here to read. http://www.linuxquestions.org/questi...&action=bbcode
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.