jrw10293
November 20th, 2007, 06:30 PM
I was working on a class for the first time the other day and could not get anything but built in data types to work as private data members. I tried creating a test program with the bare minimum code and still could not get it to work. my error is:
'string' does not name a type
I'm sure there is something simple that I'm missing, but what is it?
here's what i tried:
//---------------------------------------
specification file "Problem.h"
//---------------------------------------
class SimpleClass
{
public:
SimpleClass();
private:
string test; //this line is where i get the mentioned error
};
//-----------------------------------------
implementation file "Problem.cpp"
//-----------------------------------------
#include <cstdlib>
#include <iostream>
#include <string>
#include "Problem.h"
using namespace std;
SimpleClass::SimpleClass()
{
test="bob";
cout<<test;
}
//---------------------------------------
main file "main.cpp"
//---------------------------------------
#include <cstdlib>
#include <iostream>
#include <string>
#include "Problem.h" //compiler highlights this line
using namespace std;
int main()
{
SimpleClass ();
system("PAUSE");
return 0;
}
'string' does not name a type
I'm sure there is something simple that I'm missing, but what is it?
here's what i tried:
//---------------------------------------
specification file "Problem.h"
//---------------------------------------
class SimpleClass
{
public:
SimpleClass();
private:
string test; //this line is where i get the mentioned error
};
//-----------------------------------------
implementation file "Problem.cpp"
//-----------------------------------------
#include <cstdlib>
#include <iostream>
#include <string>
#include "Problem.h"
using namespace std;
SimpleClass::SimpleClass()
{
test="bob";
cout<<test;
}
//---------------------------------------
main file "main.cpp"
//---------------------------------------
#include <cstdlib>
#include <iostream>
#include <string>
#include "Problem.h" //compiler highlights this line
using namespace std;
int main()
{
SimpleClass ();
system("PAUSE");
return 0;
}