I've already went to the tutorials for an answer, but I don't exactly understand the purpose of c_str(). Can some enlighten me on how i can use this function and why i should use it
C++ includes the C library which uses null-terminated char arrays for strings (null-terminated means that the string ends with a byte that contains zero). Also, a string constant like "this is a string" is a null-terminated char array. To let you work with the C library, std::string() defines the c_str() member which returns a pointer to the string, followed by a null byte.
It is important to realize that the memory returned by c_str() is still owned by the string object. The memory becomes invalid the next time a non-const member function of string instance is called.