Horje
what is stdoutread in c++ Code Example
what is stdoutread in c++
// make a temp file to store the function's stdout
int newStdOut = mkstemp( "/tmp/stdout.XXXXXXX" );

// save the original stdout
int tmpStdOut = dup( STDOUT_FILENO );

// clear stdout
fflush( stdout );

// now point the stdout file descriptor to the file
dup2( newStdOut, STDOUT_FILENO );

// call the function we want to collect the stdout from
some_function();

// make sure stdout is empty
fflush( stdout );

// restore original stdout
dup2( tmpStdOut, STDOUT_FILENO );

// the tmp file now contains whatever some_function() wrote to stdout




Cpp

Related
log like printf c++ Code Example log like printf c++ Code Example
how to show constellations in starry night orion special edition Code Example how to show constellations in starry night orion special edition Code Example
how to change the value of a key in hashmp in c++ Code Example how to change the value of a key in hashmp in c++ Code Example
template c++ Code Example template c++ Code Example
round c++ Code Example round c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11