Answer to Question #25287 in C++ for Sonya

Question #25287
char psCommand[100];
sprintf(psCommand, "%s%d%s%d%s%d%s%d", "/bin/ps -f --pppid ", getppid(), ",", getpid());
system(psCommand);


These three lines of codes are written in C sharp, how would they look like in C++??
1
Expert's answer
2013-02-28T09:06:28-0500
/* First of all the code you gave is written in C.
Here's how will it look in C++ */

#include <string>
#include <sstream>
#include <cstdlib>

#include <unistd.h>

using namespace std;

int main()
{
ostringstream psCommand;
psCommand << "/bin/ps -f --pppid ";
psCommand << getppid() << "," << getpid();

system(psCommand.str().c_str());
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS