How do I declare a library within a class in C ++?

4

I need to use variables of type string , the problem is that I can not include libraries within my classes in Code :: Blocks, is there anyway to include the string / string.h library in my C ++ class ?

The code for my class:

#ifndef PROJETO_H
#define PROJETO_H


class projeto
{
private:
    string codprojeto;
    int estprojeto;
    int faseprojeto;
    int funcao;
public:
    projeto();
    bool regcod(string cod);
    string consultarcod();
};

#endif // PROJETO_H
    
asked by anonymous 23.08.2016 / 21:06

1 answer

4

You need to include the file with the string setting. There you can access its members. But you have to remember that its namespace is std , so either use the fully qualified name std::string or put a using namespace std to be able to use the simple name without "last name".

#ifndef PROJETO_H
#define PROJETO_H

#include <string>
using namespace std;

class projeto {
private:
    string codprojeto;
    int estprojeto;
    int faseprojeto;
    int funcao;
public:
    projeto();
    bool regcod(string cod);
    string consultarcod();
};

#endif // PROJETO_H
    
23.08.2016 / 21:14