简体   繁体   English

尝试在C ++中打开浏览器

[英]Attempt to open browser in C++

I am attempting to open Firefox using C++ on Linux (Ubuntu). 我试图在Linux(Ubuntu)上使用C ++打开Firefox。 However, I get an segmentation fault. 但是,我遇到了分段错误。 What am I doing wrong, and what should I do? 我在做什么错,我该怎么办?

std::cout << system("/usr/bin/firefox") << std::endl;

That code is correct. 该代码是正确的。 It will output Firefox's termination code, with a newline. 它将以换行符输出Firefox的终止代码。 Something else is causing your segmentation fault. 造成您的细分错误的其他原因。

Try running /usr/bin/firefox in a command-line, and check if it works there. 尝试在命令行中运行/ usr / bin / firefox,然后检查它是否在其中起作用。 This looks like a problem with your firefox, not your code (the part you pasted is correct). 这看起来像是您的Firefox的问题,而不是您的代码的问题(您粘贴的部分是正确的)。

To answer my own question: 要回答我自己的问题:

It works fine, as posted a few times above. 如上面几次发布,它工作正常。 The problem was that I was using Netbeans. 问题是我正在使用Netbeans。 Netbeans caused a Segmentation Fault when trying to run it. Netbeans尝试运行它时导致分段错误。 Running outside Netbeans gave the expected result. 在Netbeans之外运行可以达到预期的效果。

Nothing wrong with the code, just with Netbeans, strangely enough. 仅使用Netbeans的代码就没什么奇怪的。

So everyone with the same error, try run it outside Netbeans. 因此,每个人都有相同的错误,请尝试在Netbeans之外运行它。

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

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