60 475
Assignments Done
98,1%
Successfully Done
In April 2018

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++??
Expert's answer
/* 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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions