0

I am using the following code for a class project, but for some reason the #include string is not working, and the compiler is flagging every declaration using string. What did I do wrong?

#ifndef MEMORY_H
#define MEMORY_H
#include <string>
class Memory
{
private:
    string mem[1000];
public:
Memory()
{
    for each(string s in mem)
    {
        s = "nop";
    }
};
string get(int loc)
{
    return mem[loc];
};
void set(int loc, string input)
{
    mem[loc] = input;
}
};
#endif
Gwen Brewer
  • 87
  • 1
  • 6
  • Possible duplicate of [How do I include the string header?](http://stackoverflow.com/questions/4103169/how-do-i-include-the-string-header) – LinkBerest Nov 29 '15 at 20:12

2 Answers2

2

string is part of the std namespace, instead of string, you need:

std::string

For more on namespaces go here.

cehnehdeh
  • 527
  • 3
  • 13
1

Add this after your include statement: using namespace std;

hardcoder
  • 184
  • 2
  • 14