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("%s\n", buffer);
string cmd = bufferToString(buffer, sizeof(buffer));
printf("%s", cmd.c_str());
if (cmd.c_str() == "help") //HERE is the issue
{
printf("hello");
}
}
}
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
cmd.resize(dwRead);
if (cmd == string("help"))
and
if (0 == ::std::strcmp(buffer, "help"))
none of them work