gpt4 book ai didi

iphone - 主要在IOS中是如何工作的

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:53 24 4
gpt4 key购买 nike

我在做我的 IOS 项目时遇到了一个疑问,为了我们的测试目的,我们在 main... 中写了一段这样的代码......

printf("start\n");
FILE *fp = fopen("/Users/gui_test/Desktop/ritun/hello_test/hello_test/expt.txt", "a + b");

int a = 5, b = 5;
int c = a + b;

fprintf(fp, "%d\t", c);
fflush(fp);

fclose(fp);

printf("end \n");

我已经在 main 中注释掉以下行以测试文件写入。

return UIApplicationMain(argc, argv, nil, NSStringFromClass([ofi_video_monetAppDelegate class]));

答案已成功写入文件但两次,有人知道这是为什么吗?除了 main() 之外,如果我在其他任何地方尝试,它只写一次,main 中发生了什么。

最佳答案

查看此 Link .它解释了主要功能的使用。

main is a function that is where every C or C-based program begins. It is a reserved name, which means that you can’t have a function named main. The word int that precedes main is a declaration of the return type of the function.

int main (int argc, const char * argv[])
{
// memory management
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// printing on the log
NSLog (@"Hello, World!");

[pool drain];
//The final line tells the main method to return the value 0. Remember that the int the preceded main tells the system that this function will return a value. This value is 0. By convention, a return value of zero indicates that the function was successful.
return 0;
}

另见 NSAutoreleasePool

关于iphone - 主要在IOS中是如何工作的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com