Sorry if this is a FAQ, but I had a quick look through the
FAQ Lite and couldn't see it. Googling gives inconsistent
answers.
I'm coming from a C background. In C if I want to use
command line arguments my understanding is I must #include
<stdlib.h>.
Do I need to do a similar thing with C++? I.e., what do
I need to do if I want "int main (int argc, char **argv)"?
I've seen sites which include iostream, but that seems to
be so they can use "cout <<". I've seen sites including
stdlib.h; deprecated at best, misguided at worst. So what
should I do? is there a header file I need to use?
--
imalone 8 1730
Ian Malone wrote: I'm coming from a C background. In C if I want to use command line arguments my understanding is I must #include <stdlib.h>.
There is no such requirement. Do I need to do a similar thing with C++? I.e., what do I need to do if I want "int main (int argc, char **argv)"?
What happened when you tried it?
I've seen sites which include iostream, but that seems to be so they can use "cout <<".
The header <iostream> provides eight global objects for I/O; std::cout
is one of them.
I've seen sites including stdlib.h; deprecated at best, misguided at worst.
Irrelevant in fact.
So what should I do? is there a header file I need to use?
Try it.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
Pete Becker wrote: Ian Malone wrote:
I'm coming from a C background. In C if I want to use command line arguments my understanding is I must #include <stdlib.h>.
There is no such requirement.
Do I need to do a similar thing with C++? I.e., what do I need to do if I want "int main (int argc, char **argv)"?
What happened when you tried it?
It works, but I wanted to be sure it works because it should,
not because it happens to. (It also works in C if I leave out
stdio.h, even though I'm supposed to include it)
<snip> So what
should I do? is there a header file I need to use?
Try it.
Thanks for the reply, I was really just checking I was doing
the Right Thing. It seems that, in this regard anyway, I am.
--
imalone
Ian Malone wrote: (It also works in C if I leave out stdio.h, even though I'm supposed to include it)
There is no such requirement. Not in C++ and not in C.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
On 2005-02-18 09:13:37 -0500, Ian Malone <ib***@cam.ac.uk> said: Pete Becker wrote: Ian Malone wrote:
I'm coming from a C background. In C if I want to use command line arguments my understanding is I must #include <stdlib.h>.
There is no such requirement.
Do I need to do a similar thing with C++? I.e., what do I need to do if I want "int main (int argc, char **argv)"?
What happened when you tried it?
It works, but I wanted to be sure it works because it should, not because it happens to.
Don't worry, it works because it's supposed to.
(It also works in C if I leave out stdio.h, even though I'm supposed to include it)
Including stdio.h (or any other header) is irrelevant as to whether or
not you can get command line arguments in C or C++. The following is a
perfectly valid C and C++ program (though it doesn't do anything):
int main(int argc, char **argv)
{
for(int i=0; i<argc; ++i)
{
const char *arg = argv[i];
}
return 0;
}
--
Clark S. Cox, III cl*******@gmail.com
Pete Becker wrote: Ian Malone wrote:
(It also works in C if I leave out stdio.h, even though I'm supposed to include it)
There is no such requirement. Not in C++ and not in C.
(Checks) You're quite right, sorry. Somehow I managed
to assume it was part of the standard library. Thanks
for helping me clear this up.
--
imalone
On Fri, 18 Feb 2005 12:27:23 +0000, Ian Malone
<ib***@cam.ac.uk> wrote: Sorry if this is a FAQ, but I had a quick look through the FAQ Lite and couldn't see it. Googling gives inconsistent answers.
I'm coming from a C background. In C if I want to use command line arguments my understanding is I must #include <stdlib.h>.
Why? You need to include stdio.h for instance if you want to use I/O,
but the following is a perfectly valid program:
int main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
return 0;
}
return 0;
}
Not that it will do anything useful, but it's perfectly good syntax.
Do I need to do a similar thing with C++? I.e., what do I need to do if I want "int main (int argc, char **argv)"?
Absolutely nothing.
I've seen sites which include iostream, but that seems to be so they can use "cout <<". I've seen sites including stdlib.h; deprecated at best, misguided at worst. So what should I do? is there a header file I need to use?
No. You need to include headers to call any standard functions (you can
use the C++ versions of the C ones, like cstdlib and cstdio instead of
stdlib.h and stdio.h, if you want access to the C standard functions
which are also part of C++), but declaring main() doesn't use anything
in headers, only built-in language features.
Chris C
Chris Croughton wrote: On Fri, 18 Feb 2005 12:27:23 +0000, Ian Malone
<snip>
Thanks to everyone who replied. Sorry to drag this
ng into a discussion of C, but I've certainly found
it informative.
--
imalone
On Fri, 18 Feb 2005 15:19:54 +0000, Ian Malone
<ib***@cam.ac.uk> wrote: Chris Croughton wrote: On Fri, 18 Feb 2005 12:27:23 +0000, Ian Malone
<snip>
Thanks to everyone who replied. Sorry to drag this ng into a discussion of C, but I've certainly found it informative.
It's C++ as well as C, so it's on topic. No problem...
Chris C This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dirk Grutzmacher |
last post by:
Hi there,
My provider (strato.de) offers me this cgi, which contains some php
elements as far as I guess. I am running my page with php and would
like to include in the over all design the...
|
by: Hari |
last post by:
can i have command line arguments in VS.NET applicatio?
if yes how?
Can i have some code snippets of the above functionality?
I know we can acjieve this in console application form
command...
|
by: Jon Hewer |
last post by:
hi
i am writing a little script and currently implementing command line
arguments following the guide by mark pilgrim from dive into python;
...
|
by: amirmira |
last post by:
I would like to set command line arguments to a service at install time. I
need to do this because I need to get information from different registry
locations depending on my command line argument....
|
by: Rune Jacobsen |
last post by:
Hi,
I've been trying to figure this one out, but my experience just doesn't
have what it takes... :|
I am writing an application that reads an XML file and displays the
contents in various...
|
by: raphfrk |
last post by:
I have a program which reads in 3 filenames from the command line
prog filename1 filename2 filename3
However, it doesn't work when one of the filenames has spaces in it
(due to a directory...
|
by: Milan |
last post by:
Hi,
Please guide me how to set command line argument and
how to retrive command line argument.
Senario: vb.net application should be able to execute from command
prompt by passing login and...
|
by: dave6502 |
last post by:
Struggling newbe here, some of my #includes work, some dont. Is it
possible to list the include path ? (in BASH),
I have looked at the environmental variables (loads of them) but
cannot find a...
|
by: Jwe |
last post by:
Hi,
I've written a program which has both a command line interface
and Windows form interface, however it isn't quite working
correctly.
When run from command line with no arguments it should...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |