Reputation: 474
So I have 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 complied the program I upload it via FTP and execute dos2unix main.cpp
. I then try and 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 have no idea why this error is appearing. Anyone have any ideas?
Upvotes: 3
Views: 165
Reputation: 3209
Instead of compiling and running the code, you are running the source code directly.
What you want to do instead is the following:
g++ main.cpp -o main
./main
Upvotes: 5
Reputation: 179907
You still need to compile the program on Linux!
On Linux #
is the shell script comment character, so the first line interpreted as a shell command is using namespace std
.
Upvotes: 2