I am new to oop c++ and I am trying to better educate myself on it. One issue that I have run into is how to store a string based variable.
Everything I have tried ends up with the errors below. Any information on this would be greatly appreciated.
Here is my code.
DbConnect.h
DbConnect.cpp
Everything I have tried ends up with the errors below. Any information on this would be greatly appreciated.
Code:
DbConnect.h:7: error: ‘string’ does not name a type DbConnect.h:8: error: ‘string’ has not been declared DbConnect.h:9: error: ‘string’ does not name a type DbConnect.cpp:5: error: variable or field ‘db_set’ declared void DbConnect.cpp:5: error: ‘string’ was not declared in this scope DbConnect.cpp:9: error: ‘string’ does not name a type
DbConnect.h
Code:
#ifndef DBCONNECT_H_
#define DBCONNECT_H_
class DbConnect
{
public:
string keep_value; // private data value
void db_set(string db_value); // public method to set value
string db_get(void); // public method to get value
};
#endif /*DBCONNECT_H_*/
Code:
#include "DbConnect.h"
#include <string>
void DbConnect::db_set(string db_value){
keep_value = db_value;
}
string DbConnect::db_get(void){
return (keep_value);
}
Comment