if(pid==0){
execlp(cmd.c_str(), (char*)cmd.c_str(),0);//I entered just ls and it lists the files
_exit(EXIT_SUCCESS);
}
//wait for child
else{
int status;
waitpid(pid, &status, 0);
}
If the [first] argument contains a slash character, it is used as the pathname for this file. Otherwise, the path prefix for this file is obtained by a search of the directories passed in the PATH environment variable
That's from the documentation for the function, in the very first hit that Google gives you when you search for the function name.
You need to make a little more effort to read the documentation that's easily available. Asking people here to copy and paste information that you're too lazy to find, is, frankly, an abuse of this forum and of the people who give up their time to help others.
@MikeyBoy
Let's not abuse the young padawans for their failure to be as awesome as we are. Learning to google stuff properly (and especially to read *nix documentation!) is an acquired skill. The forum exists for all questions -- even dumb ones.