简体   繁体   English

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

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

I want to open an additional program with c++ on XCode.我想在 XCode 上用 C++ 打开一个附加程序。 It is Firefox.它是火狐。 But if I make但如果我让

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

There is an error 'ShellExecute' was not declared in this scope In other forum there was a clue to include windows.h and shellapi.h 'ShellExecute' was not declared in this scope错误在其他论坛中,有一个包含 windows.h 和 shellapi.h 的线索

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

but that makes other errors但这会导致其他错误

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

What should I do?我该怎么办? I want to open frefox with c++ in XCode on Mac?我想在 Mac 上的 XCode 中使用 c++ 打开 frefox?

ShellExecute() is only available through the Windows API. ShellExecute()只能通过 Windows API 使用。 You don't have a Windows system.您没有 Windows 系统。

You can simply use the (more portable) system() function, or one of the exec() functions available on POSIX compliant systems.您可以简单地使用(更便携的) system()函数,或 POSIX 兼容系统上可用的exec()函数之一。

Try running this in Terminal to open Firefox:尝试在终端中运行它以打开 Firefox:

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

If that does what you want, you need to wrap it in system() like this:如果这符合您的要求,则需要将其包装在system()如下所示:

#include <cstdlib>
#include <fstream>
#include <iostream>

int main()
{
    std::system("open -a Firefox");
}

I tried the same with chrome and I had to set it in inverted commas:我用 chrome 尝试了同样的方法,我不得不用引号将它设置:

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


    return 0;
}

with the apostrophe it worked!用撇号它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM