OC
- 新建 MacApp
- 修改main.m ,不需要運行循環便直接return 0 了事
測試代碼如下:
int main(int argc, const char * argv[]) {
//MacApp的編譯產物中找到可執行文件 Mac.app/Contents/MacOS/MacApp -o "hello world"
NSString *arg = [[NSUserDefaults standardUserDefaults] stringForKey:@"o"];
NSLog(@"OC打印: %@",arg);
printf("C打印: %s\n",[arg UTF8String]);
return 0;
}
然後直接 ⌘ + B 編譯一下,然後找到編譯產物目錄下的可執行文件(一般在~/Library/Developer/Xcode/DerivedData
該路徑下找快一些)
C/C++
- 創建一個命令行項目即可
- 代碼如下:
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
// gcc main.cpp -lstdc++ -o helloworld #編譯
//./helloworld "hhh" "ggg" "123" "jk666" #調用
cout << argv[0] << endl;// ./helloworld
cout << argv[1] << endl;// hhh
cout << argv[2] << endl;// ggg
cout << argv[3] << endl;// 123
cout << argv[4] << endl;// jk666
return 0;
}