The code is actually a hybrid of C and C++, and is not valid in either language.
The usage of C++ headers (iostream, string, and stack) is not valid in C. Similarly, using namespace std is C++, not C.
The usage of C's malloc() to allocate a C++ type with constructor is invalid, since C library functions do not invoke constructors for C++ objects. std::string (which is what the name string resolves to, thanks to usage of <string> and using namespace std in this case) is a (typedef for a specialiation of a) C++ template class with a constructor.
Either abandon malloc() and use operator new to dynamically allocate C++ objects or, better, use std::vector<std::string> to dynamically manage a collection of std::string.