Home > Net >  After compiling a simple C code in eclipse, it doesn't show the problems as described in my i
After compiling a simple C code in eclipse, it doesn't show the problems as described in my i

Time:09-23

I am learning C along with a script. Eclipse is my IDE and I'm using MinGW64 as a compiler. In the script there is following code written, which I am just supposed to copy and compile first:

Supposed code from script

My script says that as soon as I compile it, in the lower window under "Problems" there should be shown "0 times" and under "Console" there's supposed to be shown:

**** Build of configuration Debug for project HelloWorld **** 
Info: Internal Builder is used for build
g   -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\\main.cpp" 
g   -o HelloWorld.exe main.o
Build Finished

But instead, when I compile the same code (that's my code):

#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;

    int max;
    max = 10;

    for (int var = 0; var < max;   var)
    {
        std::cout << var << std:endl;
    }

    return 0;
}

I get following notifications under "Problems" and "Console": Problems Console

I'm definetly compiling on MinGW GCC but I don't know the reason why my Problem and Console notifications are differing from the script, I hope someone can help me.

CodePudding user response:

You've got two problems.

The easy one. On line 12 you have a typo. It should say std::endl; rather than std:endl; You are missing a colon, it's just that.

The harder one. When I load the following code into Visual Studio on Windows, it compiles and runs correctly.

#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;

    int max;
    max = 10;

    for (int var = 0; var < max;   var)
    {
        std::cout << var << std::endl;
    }

    return 0;
}

So the problem is your setup. My guess is that your include folder hasn't been set up properly. You need to tell the compiler where to look for iostream.

My gcc is at C:\tools\msys64\mingw64. The include folder is directly below this. Try which gcc on Linux or get-command gcc on Windows to locate your gcc system.

If you are on Windows, and you have enough memory in your computer you should consider Visual Studio. It's all in one really nice package, and it has a free version.

  • Related