c++ - 我运行 sudo g++ main.cpp,但它不运行程序

标签 c++ xcode macos

我正在尝试从 macOS 上的终端运行该程序。我运行这个:

sudo g++ main.cpp

但它只是“跳过”命令而不构建程序,就像这样

101:nrprim mac$ sudo g++ main.cpp 
101:nrprim mac$ 

这是代码:

#include <iostream>
using namespace std;
bool divizibil(int n, int i){
    if (n%i==0) return 1; else return 0;
}

int numarDivizori(int n){
    int i, c=0;
    for (i=1; i<=n; i++)
        if (divizibil(n,i)) c++;
    return c;
}

void prim(int n){
    int c=0;
    c=numarDivizori(n);
    if (c>2) cout<<"Numarul nu e prim"; else
        cout<<"Numarul e prim\n";

}
int main() {
    int n;
    cout<<"n=";
    cin>>n;
    prim(n);
    return 0;
}

我预计它会输出

n=

等待输入

最佳答案

它确实构建了程序,您应该在同一目录中将其视为 a.out。如果您想将其命名为其他名称,请像这样使用 -o 选项。您只需运行此 a.out 或指定的可执行文件即可运行该程序。

c++ src.cpp -o myoutput

顺便说一句,我认为您不需要 sudo

关于c++ - 我运行 sudo g++ main.cpp,但它不运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55884651/

相关文章:

c++ - QGraphicsView 中的交换小部件失败

c++ - 移除 QGraphicsView 周围的蓝色焦点边框

ios - 操作系统 X : Scene is unreachable due to lack of entry points

当我单击 XCode 4 错误/警告时,它们不会跳转到代码

ios - Swift:如何实现自定义 AutoSegue

c++ - 检索具有非常量变量的真值表的单行

c++ - 在 C++ 中生成排列的递归问题

macos - Mac 版选择器

objective-c - 如何以编程方式获取mac的存储容量?

macos - bash - 从文本文件中删除多行不同的文本