什么是(int main(int argc,char argv []))的意思? [英] what is(int main(int argc, char argv[]) ) means?

查看:96
本文介绍了什么是(int main(int argc,char argv []))的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


这一行的含义是什么:

hi
what is this line means :

int main(int argc, char argv[])  



它做了什么?



以及这个:


and what does it does?

and too this:

int _tmain(int argc, _TCHAR* argv[])





以及它们之间有什么区别:



and what is the difference between those and follows :

int main ()



请解释一下



谢谢


please explain it simply

thanks

推荐答案

int main(int argc, char *argv[])
int main ()



这些是根据C ++标准的任何程序的入口点d。第一个是命令行参数,第二个是没有它们。




These are the entry points of any program according to C++ standard. The first is with the command line parameters, second is without them.

int _tmain(int argc, _TCHAR* argv[])



这是微软的扩展到C ++标准入口点。它具有多字节和unicode字符串兼容性。



upd。

关于ISO C ++标准3.6.1中的主要内容

http://www.open-std.org/jtc1/ sc22 / wg21 / docs / papers / 2005 / n1905.pdf [ ^ ]

请参阅第51页


This is Microsoft''s extension to C++ standard entry point. It made for multibyte and unicode strings compatibility.

upd.
About main in ISO C++ standard 3.6.1
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf[^]
Please see page 51


用户可以使用<运行程序命令行参数,例如:

A user can run your program with command-line parameters, for example:
youApplication.exe param1 -i filename.txt /verbose



在此示例中,用户传递参数param1, - i,filename.txt和/ verbose。它们的意思完全由您的应用程序定义。



您可以通过 main 的参数访问这些参数节目。第一个参数为您提供命令行参数的数量,第二个参数为字符串数组,为您提供参数值。



这是您的业务解释它们用作用户输入。







请参阅:http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B [ ^ ]。



-SA


In this example, the user passes the parameters "param1", "-i", "filename.txt" and "/verbose". That they mean is totally defined by your application.

You can access these parameters via the arguments of main you show. First parameter gives you the number of command line parameters, and the second one, array of strings, gives you the parameter values.

It''s your business to interpret them and use as the user input.



Please see: http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B[^].

—SA


C ++语言源自C,它最初是基于控制台的语言。 apimain()(带或不带参数)是程序的入口点。如果您不提供参数,则会调用api并且您的程序无法看到可能已传递给程序的任何参数。



移动几个几十年来,Microsoft Windows支持ANSI和UNICODE。 API _tmain是一个宏,它根据_UNICODE宏扩展到程序入口点main(ANSI)或wmain(UNICODE)。从VC2005(?)开始,启用UNICODE的程序(即_UNICODE定义)将_tmain扩展为wmain(不是main),_TCHAR扩展为wchar_t。



可以在此处 [ ^ ]。请注意文本中有一些方括号,这些方括号容易混淆,可能会被误解。
C++ as a language is derived from C, which was originally a console based language. The api "main()" (with or without parameters) is the entry point to your program. If you do not provide parameters, the api is called and your program is not able to see any parameters that may have been passed to the program.

Moving along a few decades now, Microsoft Windows supports ANSI and UNICODE. The API _tmain is a macro that expand to the program entry point main (ANSI) or wmain (UNICODE) according to _UNICODE macro. Starting with VC2005 (?), a program that is UNICODE enabled (ie. _UNICODE defined) will expand _tmain to wmain (not main) and _TCHAR expands to wchar_t.

The Microsoft explanation can be found here[^]. Beware that they have some square brackets in the text that are confusing and can be misinterpreted.


这篇关于什么是(int main(int argc,char argv []))的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆