使用Eclipse运行C代码的.exe文件

时间:2013-10-06 09:16:33

标签: c++ c eclipse exe eclipse-cdt

我使用Eclipse IDE在C语言中创建了一个非常简单的基本代码。

Eclipse详细信息:

  • 适用于C / C ++开发人员的Eclipse IDE
  • 版本:Juno Service Release 2
  • 构建ID:20130225-0426

以下是代码:

#include <stdio.h>

int main( int argc, char ** argv ) {
    printf("Hello, World!\n");
    return 0;
}

在Eclipse中成功运行,它生成.exe&amp; Project / Debug目录中的.o文件。我试图运行该.exe文件,但它无法正常工作。

Eclipse就好像它很快运行程序然后终止它一样。窗口出现,但是当我运行.exe时没有任何反应。它只是一个对话框的闪光灯。

应该是什么问题?我不想更改IDE,我已经尝试过这两件事:

3 个答案:

答案 0 :(得分:0)

Windows正在为您的程序打开命令提示符,运行print语句,然后关闭窗口(因为您的功能已经结束)。

如果要查看程序的结果,请运行命令提示符,导航到.exe文件的目录,然后从那里运行。

答案 1 :(得分:0)

你也应该试试这个:

项目浏览器视图中右键单击项目名称,然后转到运行方式并单击本地C / C ++应用程序

答案 2 :(得分:0)

从命令提示符窗口运行程序。如果你简单地双击exe文件..它只是运行程序并立即关闭。你没有时间看到它。

通过导航到目录并执行cmd

,在./yourexefile窗口中运行它

或者通过双击来执行此操作的可怕方法是:

#include <stdio.h>

int main( int argc, char ** argv ) {
   int n;
   printf("Hello, World!\n");
   scanf("%d",&n); // this will force the execution window to stay open until you put in some input
   return 0;
}

你也可以这样做:

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char ** argv ) {
   printf("Hello, World!\n");
   system("pause");
   return 0;
}

另一种方式(更美观):

#include <stdio.h>

int main( int argc, char ** argv ) {
   printf("Hello, World!\n");
   printf(" Press enter to exit\n");
   getchar();
   return 0;
}
相关问题