在Mac上用c++打开一个附加程序[XCode]

Open an additional program with c++ on Mac [XCode]

本文关键字:一个 程序 XCode c++ 上用 Mac      更新时间:2023-10-16

我想在XCode上用c++打开一个额外的程序。它是火狐。但如果我做

Shell Execute("file://localhost/Applications/Firefox.app"); 

出现错误'ShellExecute' was not declared in this scope在另一个论坛中,有一条线索包括windows.h和shellapi.h

#include <shellapi.h>
#include <windows.h>

但这会导致其他错误

shellapi.h: No such file or directory
windows.h: No such file or directory

我该怎么办?我想在Mac上用XCode中的c++打开frefox?

尝试在终端中运行此程序以打开Firefox:

open -a Firefox http://www.ibm.com

如果这是你想要的,你需要像这样用system()包装它:

#include <cstdlib>
#include <fstream>
#include <iostream>
int main()
{
    std::system("open -a Firefox");
}

ShellExecute()仅通过Windows API提供。您没有Windows系统。

您可以简单地使用(更便携的)system()函数,或者在符合POSIX的系统上可用的exec()函数之一。

我对chrome也做了同样的尝试,我不得不用引号设置它:

int main() {
    system("open -a 'Google Chrome'");

    return 0;
}

用撇号就行了!

相关文章: