How do I export a C ++ project on a Windows PC and run it on Linux?

So I just started learning C ++ and I want to test my first program on Linux. Here is my program:

#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;
}

      

I am using Bloodshed to compile the program. After I have executed the program, I upload it via FTP and execute dos2unix main.cpp

. Then I try to run the program, but I get this error:

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

      

I don't know why this error appears. Does anyone have any idea?

+3


source to share


2 answers


Instead of compiling and running your code, you use the source code directly.

Instead, you should do the following:



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

      

+5


source


You still need to compile the program on Linux!



Linux #

has a shell comment character script, so the first line interpreted as a shell command is using namespace std

.

+2


source







All Articles