popen catching output and errors

I have code which at the moment only catches the command/program output if the program runs correctly, which is a small problem as I would like to capture everything from stdout inclusive of errors

FILE *fp;
fp = popen(command.c_str(), "r");
while(fgets(cbuf, 1024, fp) != NULL){
.....do stuff here....
}
pclose(fp);

Can anyone tell me where I am going wrong here ?

(Code is being compiled on ubuntu and debian)
Regards
Michael

It has nothing to do with your C++ code. command.str() needs to look like this:

some command 2&>1

This redirects stderr to stdout, so both streams will be merged and returned as stdout to your program.