加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何在Windows PC上导出C项目并在Linux上运行?

发布时间:2020-12-14 05:44:51 所属栏目:Windows 来源:网络整理
导读:所以我刚开始学习C,我想在 Linux上测试我的第一个程序.这是我的计划: #include cstdlib#include iostream#define ANSI_COLOR_RED "x1b[31m"#define ANSI_COLOR_GREEN "x1b[32m"#define ANSI_COLOR_YELLOW "x1b[33m"#define ANSI_COLOR_BLUE "x1b[34m"#d
所以我刚开始学习C,我想在 Linux上测试我的第一个程序.这是我的计划:

#include <cstdlib>
#include <iostream>

#define ANSI_COLOR_RED     "x1b[31m"
#define ANSI_COLOR_GREEN   "x1b[32m"
#define ANSI_COLOR_YELLOW  "x1b[33m"
#define ANSI_COLOR_BLUE    "x1b[34m"
#define ANSI_COLOR_MAGENTA "x1b[35m"
#define ANSI_COLOR_CYAN    "x1b[36m"
#define ANSI_COLOR_RESET   "x1b[0m"

using namespace std;



void main_header()
{
     printf (ANSI_COLOR_GREEN  "+---------------+---------------| " ANSI_COLOR_RESET  "n");
     printf (ANSI_COLOR_GREEN  "+---------" ANSI_COLOR_RED " THE GENERAL "  "---------|" ANSI_COLOR_RESET  "n");
     printf (ANSI_COLOR_GREEN  "+---------------+---------------| " ANSI_COLOR_RESET  "n");
}

int main()
{
    main_header();
    system("PAUSE");
    return EXIT_SUCCESS;
}

我正在使用Bloodshed来编译程序.在我完成程序后,我通过FTP上传它并执行dos2unix main.cpp.然后我尝试运行该程序,但我收到此错误:

./main.cpp: line 12: using: command not found
./main.cpp: line 16: syntax error near unexpected token `('
./main.cpp: line 16: `void main_header()'

我不知道为什么会出现这个错误.有人有主意吗?

解决方法

您不是直接编译和运行代码,而是直接运行源代码.

您想要做的是以下内容:

g++ main.cpp -o main
./main

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读