0

I'm getting an error running a Hello World Program using Eclipse. I have installed MinGW and Cygwin, I know I only need one but I have other editor that uses one but not the other. I have checked the Paths and Symbols under GCC C++ Compiler, it links to directories which contain the include files. However, I am still getting an unresolved inclusion error on the include files. I'm using Windows 7. My Code:

#include <iostream>
#include <strings>
using namespace std;

int main()
{

    string yourName;

    cout << "Enter your name: ";
    cin >> yourName;
    cout << "Hello " << yourName << endl;
    return 0;
}

This is the detailed error

Description                         Resource Path                   Location Type
Symbol 'cin' could not be resolved  test.c  /hello_world/src    line 17 Semantic Error
Symbol 'cout' could not be resolved test.c  /hello_world/src    line 16 Semantic Error
Symbol 'cout' could not be resolved test.c  /hello_world/src    line 18 Semantic Error
Symbol 'endl' could not be resolved test.c  /hello_world/src    line 18 Semantic Error
Type 'namespace' could not be resolved  test.c  /hello_world/src    line 10 Semantic Error
Type 'string' could not be resolved test.c  /hello_world/src    line 14 Semantic Error

Any help? thanks

1 Answers1

1

Most likely, you have selected to create a C project, in which case Eclipse sets up your tool chain to use the C compiler only.

Since you are using C++, you should create a C++ project and create your source files with a .cpp extension.

You could also try to convert the existing C project into a C++ project by adjusting the settings in the project properties, but it is usually easier to just create a new project and copy the files over (especially since you seem to just starting, and not have a big code base).

As you can see in the following picture, SimpleC has been created as C-project - there, your source code shows errors (even though I have renamed it to .cpp).

The SimpleCpp project was created as C++ project - there, the source code does not show any errors.

enter image description here

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123