string type does name a type even after adding <string>

I don't know what I am doing wrong.I have been trying to figure out the problem for an hour now and nothing works. I am working on header file and implementation file.
Here is the code in specification file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>

class Employee
{
    private:
        string name;
        string department;
        string position;
        int idNumber;
    public:
        Employee::Employee(string empName, int empID, string empDept, string empPost );

        Employee::Employee(string empName, int empID);
        // Default constructor
        Employee();
};
#endif // EMPLOYEE_H 


Here is the code in implementation file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "Employee.h"
#include <iostream>
#include <string>

using namespace std;

Employee::Employee(string empName, int empID, string empDept, string empPost)
{
      name = empName;
      idNumber = empID;
      department = empDept;
      position  = empPost;
}

Employee::Employee(string empName, int empID)
{
    name = empName;
    idNumber = empID;
    department = "";
    position = "";
}

Employee::Employee()
{
    name = ""; idNumber = 0; department = "" ; position = "";
}


I just keep getting the same error 'string' does not name a type.
string exists in the namspace std. So you should use it as std::string.

Due to line 5 in your implementation file the content of namespace std is 'moved' to the global namespace so that you don't need std::
closed account (E0p9LyTq)
You are declaring "using namespace std;" after you include your header file. That is why your compiler is complaining "'string' does not name type."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

class Employee
{
private:
   std::string name;
   std::string department;
   std::string position;
   int idNumber;

public:
   Employee(std::string empName, int empID, std::string empDept, std::string empPost);
   Employee(std::string empName, int empID);
   // Default constructor
   Employee();
};
#endif // EMPLOYEE_H 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include "Employee.h"

// using namespace std;

Employee::Employee(std::string empName, int empID, std::string empDept, std::string empPost)
{
   name = empName;
   idNumber = empID;
   department = empDept;
   position  = empPost;
}

Employee::Employee(std::string empName, int empID)
{
   name = empName;
   idNumber = empID;
   department = "";
   position = "";
}

Employee::Employee()
{
   name = "";
   idNumber = 0;
   department = "" ;
   position = "";
}

This is a good example why "using namespace std;" can cause problems that are hard for beginners to track down.
Thank you guys so much. Have a lot to learn.
Topic archived. No new replies allowed.