freopen
场景:
1.比如控制台打打印太长了,需要记录到文件上分析。
2.或者是做一些简单的日志工作就可以用到freopen。
代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <io.h>
#include <assert.h>
using namespace std;
char *GetFileDirectory(const char *filename) {
char *ret = NULL;
char dir[1024];
char *cur;
if (filename == NULL) return(NULL);
#if defined(WIN32) && !defined(__CYGWIN__)
# define IS_SEP(ch) ((ch=='/')||(ch=='\\'))
#else
# define IS_SEP(ch) (ch=='/')
#endif
strncpy