I am outputting to stdout. How can I redirect that to a new file through code? While we run the program we can redirect like ./sample > test.txt
. How can I do this when executing the sample program itself ? (C programming)
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Use
freopen()
.Use
dup2()
system call and redirect the output to a file.You probably want to use freopen.
Example from reference: