using the string class inside anther class

Hello all, I'm getting quite frustrated with this. I'm trying to create an instance of a string class inside my original class. It keeps giving me this error:

error: 'string' does not name a type

Here is my code in my header file:

#ifndef _HASHTABLE_H
#define _HASHTABLE_H
#include <string>
#include <iostream>

class HashTable{
public:

struct HashTableCell{
string key;
string correctspell;
int status;
};
};


#endif /* _HASHTABLE_H */



I'm programming using Xcode on my macbook. But it gives me the same error in microsoft visual studios 2008. I'm just not sure how to create a class inside another class I guess. Thanks for any help! -James
you're not in the std namespace

either throw in a using namespace std; after your includes, or define your strings as std::string key;
closed account (z05DSL3A)
As it is in a header file it is best to use scope resolution.
e.g.
1
2
3
4
5
    struct HashTableCell{
        std::string key; 
        std::string correctspell; 
        int status; 
    };

wow, I feel dumb... heh, thanks a lot! Now that I have learned the hard way, I should remember that. :] Thanks again Disch!
okay, will do Grey Wolf. Keep the cost of running the program down to a minimum using the scope resolution. Thanks!
You can also specify

1
2
#include <string>
using std::string;


In a header, without causing problems in most cases (anyone who includes your header file will see the class name "string" defined). This is unlike

using namespace std; // evil

which is a very anti-social.
Topic archived. No new replies allowed.