main函数中的参数有什么用?main前面的_t如何理解
main函数中的参数有什么用?main前面的_t怎么理解?
------解决思路----------------------
程序是要被系统调用的,main的参数是系统传给程序的参数。
比如你输入一些命令行,这些命令可以附加一些参数,这些参数就是系统传给main的。
tmain只是main的马挂,最后还是转成main
------解决思路----------------------
tmain是main在一个平台上的另一个名字
在中国你叫A,美国你叫a。A和a都是你自己
------解决思路----------------------
有个东西叫做搜索引擎,很好用
------解决思路----------------------
------解决思路----------------------
说的太对了
和main里面的参数一模一样
第一个表示参数个数
第二个表示参数值
不知道你是否用过DOS命令
比如
dir /s
argc 为2,
argv[0] 为dir argv[1] 为/s
------解决思路----------------------
http://bbs.****.net/topics/390469280
//比较int
int max1(int value1,int value2)
{
return (value1>value2 ? value1:value2);
}
//比较double
double max1(double value1,double value2)
{
return (value1>value2 ? value1:value2);
}
//比较char
char max1(char value1,char value2)
{
return (value1>value2 ? value1:value2);
}
//比较string
string max1(string value1,string value2)
{
return (value1>value2 ? value1:value2);
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<max1(10,20)<<endl;
cout<<max1(12.58,8.48)<<endl;
cout<<max1('a','f')<<endl;
cout<<max1("abc","def")<<endl;
return 0;
}
------解决思路----------------------
程序是要被系统调用的,main的参数是系统传给程序的参数。
比如你输入一些命令行,这些命令可以附加一些参数,这些参数就是系统传给main的。
tmain只是main的马挂,最后还是转成main
------解决思路----------------------
tmain是main在一个平台上的另一个名字
在中国你叫A,美国你叫a。A和a都是你自己
------解决思路----------------------
有个东西叫做搜索引擎,很好用
http://baike.baidu.com/view/3478231.htm?fr=aladdin
------解决思路----------------------
A Sample Generic-Text Program
Microsoft Specific —>
The following program, GENTEXT.C, provides a more detailed illustration of the use of generic-text mappings defined in TCHAR.H:
/*
* GENTEXT.C: use of generic-text mappings defined in TCHAR.H
* Generic-Text-Mapping example program
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <errno.h>
#include <tchar.h>
int __cdecl _tmain(int argc, _TCHAR **argv, _TCHAR **envp)
{
_TCHAR buff[_MAX_PATH];
_TCHAR *str = _T("Astring");
char *amsg = "Reversed";
wchar_t *wmsg = L"Is";
#ifdef _UNICODE
printf("Unicode version\n");
#else /* _UNICODE */
#ifdef _MBCS
printf("MBCS version\n");
#else
printf("SBCS version\n");
#endif
#endif /* _UNICODE */
if (_tgetcwd(buff, _MAX_PATH) == NULL)
printf("Can't Get Current Directory - errno=%d\n", errno);
else
_tprintf(_T("Current Directory is '%s'\n"), buff);
_tprintf(_T("'%s' %hs %ls:\n"), str, amsg, wmsg);
_tprintf(_T("'%s'\n"), _tcsrev(str));
return 0;
}
If _MBCS has been defined, GENTEXT.C maps to the following MBCS program:
/*
* MBCSGTXT.C: use of generic-text mappings defined in TCHAR.H
* Generic-Text-Mapping example program
* MBCS version of GENTEXT.C
*/
#include <stdlib.h>
#include <direct.h>
int __cdecl main(int argc, char **argv, char **envp)
{
char buff[_MAX_PATH];
char *str = "Astring";
char *amsg = "Reversed";
wchar_t *wmsg = L"Is";
printf("MBCS version\n");
if (_getcwd(buff, _MAX_PATH) == NULL) {
printf("Can't Get Current Directory - errno=%d\n", errno);
}
else {
printf("Current Directory is '%s'\n", buff);
}
printf("'%s' %hs %ls:\n", str, amsg, wmsg);
printf("'%s'\n", _mbsrev(str));
return 0;
}
If _UNICODE has been defined, GENTEXT.C maps to the following Unicode version of the program. For more information about using wmain in Unicode programs as a replacement for main, see Using wmain in C Language Reference.
/*
* UNICGTXT.C: use of generic-text mappings defined in TCHAR.H
* Generic-Text-Mapping example program
* Unicode version of GENTEXT.C
*/
#include <stdlib.h>
#include <direct.h>
int __cdecl wmain(int argc, wchar_t **argv, wchar_t **envp)
{
wchar_t buff[_MAX_PATH];
wchar_t *str = L"Astring";
char *amsg = "Reversed";
wchar_t *wmsg = L"Is";
printf("Unicode version\n");
if (_wgetcwd(buff, _MAX_PATH) == NULL) {
printf("Can't Get Current Directory - errno=%d\n", errno);
}
else {
wprintf(L"Current Directory is '%s'\n", buff);
}
wprintf(L"'%s' %hs %ls:\n", str, amsg, wmsg);
wprintf(L"'%s'\n", wcsrev(str));
return 0;
}
If neither _MBCS nor _UNICODE has been defined, GENTEXT.C maps to single-byte ASCII code, as follows:
/*
* SBCSGTXT.C: use of generic-text mappings defined in TCHAR.H
* Generic-Text-Mapping example program
* Single-byte (SBCS) Ascii version of GENTEXT.C
*/
#include <stdlib.h>
#include <direct.h>
int __cdecl main(int argc, char **argv, char **envp)
{
char buff[_MAX_PATH];
char *str = "Astring";
char *amsg = "Reversed";
wchar_t *wmsg = L"Is";
printf("SBCS version\n");
if (_getcwd(buff, _MAX_PATH) == NULL) {
printf("Can't Get Current Directory - errno=%d\n", errno);
}
else {
printf("Current Directory is '%s'\n", buff);
}
printf("'%s' %hs %ls:\n", str, amsg, wmsg);
printf("'%s'\n", strrev(str));
return 0;
}
See Also Generic-text mappings, Data type mappings, Constants and global variable mappings, Routine mappings, Using generic-text mappings
END Microsoft Specific
------解决思路----------------------
说的太对了
和main里面的参数一模一样
第一个表示参数个数
第二个表示参数值
不知道你是否用过DOS命令
比如
dir /s
argc 为2,
argv[0] 为dir argv[1] 为/s
------解决思路----------------------
http://bbs.****.net/topics/390469280