Topic: int main(vector<string>) ?
Author: "Jim Cobban" <Jim.Cobban.jcobban@nt.com>
Date: 1998/09/09 Raw View
Since it appears that one of the objectives of future evolution of C++ is to
replace the UNIX-centric NUL-terminated character strings with the STL
std::string, would it not be logical to add another version of main which
accepts a vector of string as an alternative to the existing argc/argv
format?
--
Jim Cobban | jcobban@nortel.ca | Phone: (613) 763-8013
Nortel (MCS) | | FAX: (613) 763-5199
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/09/09 Raw View
On 9 Sep 1998 19:56:52 GMT, Jim Cobban <Jim.Cobban.jcobban@nt.com> wrote:
>Since it appears that one of the objectives of future evolution of C++ is to
>replace the UNIX-centric NUL-terminated character strings with the STL
>std::string, would it not be logical to add another version of main which
>accepts a vector of string as an alternative to the existing argc/argv
>format?
What happens if we weren't using std::vector std::string but rather
myspace::vector myspace::string.
But I still like the idea. How about
int main(const valarray<string>) throw();
where valarray and string are arbirary classes that are similar to
std::valarray and std::string.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/09/10 Raw View
"Jim Cobban" <Jim.Cobban.jcobban@nt.com> writes:
>Since it appears that one of the objectives of future evolution of C++ is to
>replace the UNIX-centric NUL-terminated character strings with the STL
>std::string, would it not be logical to add another version of main which
>accepts a vector of string as an alternative to the existing argc/argv
>format?
Null-terminated strings are not especially Unix-centric. A string
needs to indicate its end somehow. The two most popular ways are
by prepending a "length" field, and termination with a special
character such as null. (A third way is setting an unused bit in
the last character, an unsuitable technique for 8-bit chars.)
Perhaps you mean the argc/argv convention.
C++ uses the same main program interface as C for compatibility.
For modern programs using a GUI, the main function is irrelevant,
and typically a program doesn't have main as "the entry point".
For programs using argc/argv in main, I don't see a lot of
advantage in being required to receive strings instead of
char arrays.
With argc/argv, you can use the existing C libraries for dealing
with program arguments (like the Unix-centric "getopt" ;-). If
main received strings, such existing library code would need to be
be rewritten to deal with strings. (It isn't sufficient just to
extract a char array with c_str(), because the library functions
expect to be passed an array of char*). Existing code dealing with
argc/arv would also need to be rewritten. What benefit is gained
to justify the rewriting?
If you want to treat the program arguments as strings, you can
easily convert all the arguments to a vector of strings with a
few lines of code. A standard C++ library function that takes argc
and argv and produces a vector of strings might be a reasonable
addition.
--
Steve Clamage, stephen.clamage@sun.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/09/10 Raw View
Steve Clamage <stephen.clamage@sun.com> writes:
> A standard C++ library function that takes argc and argv and
> produces a vector of strings might be a reasonable addition.
Such as:
inline std::vector<std::string> argv2vecstr(int argc, char *argv[]) {
return std::vector<std::string>(argv, argv+argc);
}
IMO, the greatest inconvenient of adopting vector<string> instead of
(int,char*[]) is that <vector> and <string> must be included...
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]