Can I declare a library within a class in C++?

Asked

Viewed 117 times

4

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

The code of 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
  • 1

    I didn’t quite understand your question! The standard library classes work normally in codeblocks; you just need to include the string. h; have you tried this? If so, what kind of error appeared?

1 answer

4


You need to include the file with the definition of string. Then you can access your members. But you have to remember that his namespace is std, then either use the fully qualified name std::string or puts a using namespace std 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

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • Ow,vlw bro,was that right,I wasn’t able to include that library,but now I see it’s because I didn’t use the Std namespace,vlws:D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.