3

I have the following #include in my program which I am trying to change from a console app to a GUI app. I have to code this by hand. The problem is my program can't import the string header. Why is that?

#ifndef CATALOG_H_
#define CATALOG_H_
#include <string>


#include "StudentRepository.h"

#include "Student.h"


using namespace std;

class Catalog{
private:
    StudentRepository *studRepo;

public:
    Catalog(StudentRepository *stre):studRepo(stre){};
    ~Catalog();
    void addNewStudent(string name, int id, int group);
    void removeStudent(string name);
    void editStudent(string,int,int);
    Student seachStudent(string name);
    void printStudents();
          .
          .
          .

};

#endif /* CATALOG_H_ */

ERROR:

Description Resource    Path    Location    Type
Type 'string' could not be resolved Catalog.h   /L_6-8_GUI  line 25 Semantic Error

PS: I use Eclipse with the QT addon.

Joe
  • 41,484
  • 20
  • 104
  • 125
Bogdan M.
  • 2,161
  • 6
  • 31
  • 53
  • 1
    What is the problem? is it you are including it in program, but not getting the library functions? – ScarCode May 29 '12 at 15:13
  • There is nothing in your question to do with Qt: removed tag. – Samuel Harmer May 29 '12 at 15:16
  • Well otherwise the include work as soon i moved to Qt project it dosent make the imports... – Bogdan M. May 29 '12 at 15:18
  • i get error on page it cant see the include. – Bogdan M. May 29 '12 at 15:19
  • 3
    @user1388172: Post error message. Error messages ARE important, so "forgetting" to post EXACT error message is a VERY bad idea. – SigTerm May 29 '12 at 15:33
  • 4
    Sidenote: Do not use `using namespace std;` in header files. It imports all symbols which are in namespace std up to that point, and you never know which symbols these are (because the standard will be updated, and because the standard does not define which headers are included by which standard headers). I had real life experience with legacy code that stopped compiling once I switched to more recent compiler versions. Not only are there standard symbols imported, but also non-standard ones. – Sebastian Mach May 29 '12 at 15:57
  • 4
    Do you have your include paths in eclipse correct? It could be that they are correctly setup in QT (the IDE I mean) and not in Eclipse. – Dennis May 29 '12 at 15:58
  • You might just need to add the correct include path to the C++ standard libraries to your eclipse project. 'Semantic error' points to string is not seen by the indexer. The other option is to disable 'Symbol is not resolved' in the 'Syntax and Semantic Errors' section of the Code Analysis project settings. – πάντα ῥεῖ May 29 '12 at 16:21
  • Those aren't even three dozen lines of code, and at a first glance I see that you are [`using namespace std`](http://stackoverflow.com/a/2880136/140719), store naked pointers, and [pass strings by value](http://stackoverflow.com/a/2139254/140719). You might want to get yourself [a good book](http://stackoverflow.com/q/388242/140719) ASAP. – sbi May 29 '12 at 16:48

1 Answers1

2

write std::string, not just string.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331