comparing char buffer to string not working

When trying to compare a char buffer to a std string in an if statement it’s not working as intended Here is the code

if (ConnectNamedPipe(hPipe, NULL) != FALSE)   // wait for someone to connect to the pipe
        while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE)
            /* add terminating zero */
            buffer[dwRead] = 0x00;

            /* do something with data in buffer */
            printf("%sn", buffer);
            string cmd = bufferToString(buffer, sizeof(buffer));

            printf("%s", cmd.c_str());

            if (cmd.c_str() == "help") //HERE is the issue


When comparing it doesn’t work I’ve tried using different types of conversions of char buffer[1024] to a string but not getting anywhere

EDIT: I’ve tried so far

if (cmd == string("help")) 


if (0 == ::std::strcmp(buffer, "help"))

none of them work


Instead of reading the data into a char[] and then copying that data into a std::string, you could use a std::string directly.

Building blocks:

std::string cmd;

cmd.resize(wanted_buffer_size); // Set the proper buffer size

ReadFile(hPipe,, cmd.size(), &dwRead, nullptr); // Read directly into cmd

cmd.resize(dwRead); // Shrink down to dwRead afterwards. Automatically null terminated.