Remove all adjacent duplicates in a string using a Stack Input: careermonk
     Output:    camonk
  
  Input: mississippi
     Output:    m


I want to improve this code.

#include &lt;iostream&gt;
#include &lt;string&gt;

#define max 1000

class Stack
{
  int top;
public:
  char stk[max];
  Stack()
  {
    top = -1;
  }
  bool isStackEmpty();
  void push(char);
  char pop();
  std::string modifyString(std::string);
private:
  void removeAdjacentDuplicate(std::string);
};

bool Stack::isStackEmpty()
{
   if (top == -1)
      return true;
   else
      return false;
}

void Stack::push(char val)
{
   int s = max - 1;
   if (top &lt; s)
   {
     top = top + 1;
     stk[top] = val;
   }
   else
    std::cerr &lt;&lt; "Stack Overflow \n";
}

char Stack::pop()
{
   if (isStackEmpty() == true)
       std::cerr &lt;&lt; "Stack Underflow \n";
   else
   {
      --top;
      return stk[top + 1];
   }
}

void Stack::removeAdjacentDuplicate(std::string str)
{
   int len = str.length();
   for (int i = 0; i &lt; len; i++)
   {
      if (isStackEmpty() == true)
      {
         push(str[i]);
      }
      else if (str[i] == stk[top])
      {
         int discard = pop();
      }
      else
      {
         push(str[i]);
      }
   }
}

std::string Stack::modifyString(std::string str)
{
   removeAdjacentDuplicate(str);
   str.resize(top + 1);
   for (int i = 0; i &lt;= top; i++)
   {
     str[i] = stk[i];
   }
   str[top + 1] = '\0';
   return str;
}

int main()
{
   Stack stack1;
   std::string str = "careermonk";
   std::cout &lt;&lt; "Orignal string : " &lt;&lt; str &lt;&lt; "\n";
   str = stack1.modifyString(str);
   std::cout &lt;&lt; "New string     : " &lt;&lt; str &lt;&lt; "\n";

   Stack stack2;
   std::string str2 = "mississippi";
   std::cout &lt;&lt; "Original string : " &lt;&lt; str2 &lt;&lt; "\n";
   str2 = stack2.modifyString(str2);
   std::cout &lt;&lt; "New string      : " &lt;&lt; str2 &lt;&lt; "\n";
}
std::array

You could use std::array and get rid of max define. In general, I'd like to suggest avoiding defines which can conflict with any stl names by any cost. 

One of Windows header has its own #define max and this is horrible when your code wants std::numeric_limits&lt;int&gt;::max(), std::max({a, b, c}), etc.

Things are even worse if you're writing header only library:

#if defined max
#  undef max
#  define HAD_MAX
#endif 

// ... C++ code ...

#if defined HAD_MAX
#  define max(a, b) ... // copy-paste from Windows.h
#endif


Stack::removeAdjacentDuplicate signature

Signature of Stack::removeAdjacentDuplicate(std::string) can be improved:

At least, it doesn't actually removes anything. It perform some kind of initialization from given string, so consider choosing more intuitive name. 

Additionally, avoid copying parameter - you can use const std::string&amp;

Stack::modifyString

Stack::modifyString also says nothing about its purpose and it also constructs another string instead of modifying something. Consider better naming. 

Use standard library

When copying N characters, consider using standard library functions instead of for loop: strncpy, memcpy, std::copy_n and others works fine, looks clear and may perform some performance optimizations. 

Use standard library (alternative)

As alternative, you can construct new string directly from Stack::stk. There is corresponding constructor: std::string(const char* s, size_t n);. In this case you can pass all std::string parameters by const reference. 

BTW, I'm assure you're already bored with my variable naming suggestions, so I don't need to add another one here :)

Non-const public members are dangerous

Consider using some naming conventions

It's hard to determine whether some variable is a class member or not. In order to simplify your work, make member variables somehow. You can use m_member, member_, etc.