C/C++文件重定向的几种方式
2014-10-31 14:50
106 查看
这篇文章也谈不上原创,只是总结了C/C++文件重定向的几种方式:
注意:转载说明出处 chinabinlang 的CSDN ;
方法一:
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
void main( void )
{
stream = freopen( "freopen.out", "w", stderr );
if( stream == NULL )
fprintf( stdout, "error on freopen/n" );
else
{
fprintf( stream, "This will go to the file 'freopen.out'/n" );
fprintf( stdout, "successfully reassigned/n" );
fclose( stream );
}
system( "type freopen.out" );
}
方法二:
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ofstream log("foo.txt");
streambuf * oldbuf = cout.rdbuf(log.rdbuf());
cout << "重定向的内容/n" ;
return 0;
}
方法三:
freopen("r.txt", "r", stdin );
freopen("r.txt", "w", stdout);
freopen("r.txt", "w", stderr);
方法四:
控制台重定向:常用于MFC于控制台的结合:
AllocConsole();
freopen("CON", "w", stdout );
注意:转载说明出处 chinabinlang 的CSDN ;
方法一:
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
void main( void )
{
stream = freopen( "freopen.out", "w", stderr );
if( stream == NULL )
fprintf( stdout, "error on freopen/n" );
else
{
fprintf( stream, "This will go to the file 'freopen.out'/n" );
fprintf( stdout, "successfully reassigned/n" );
fclose( stream );
}
system( "type freopen.out" );
}
方法二:
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ofstream log("foo.txt");
streambuf * oldbuf = cout.rdbuf(log.rdbuf());
cout << "重定向的内容/n" ;
return 0;
}
方法三:
freopen("r.txt", "r", stdin );
freopen("r.txt", "w", stdout);
freopen("r.txt", "w", stderr);
方法四:
控制台重定向:常用于MFC于控制台的结合:
AllocConsole();
freopen("CON", "w", stdout );
相关文章推荐
- C/C++文件重定向的几种方式
- C/C++_文件重定向的几种方式
- 文件打开的几种方式(c/c++/win32/mfc)
- C++ 判断文件的几种方式
- 文件打开的几种方式(c/c++/Windows)
- 文件打开的几种方式(c/c++/Windows)
- C++文件读写之获取文件大小的几种常见的方式
- C/C++读写excel文件 的几种方式
- JSP文件下载的几种方式
- .netFramework1.1下创建文件几种方式的不同之处
- JSP文件下载的几种方式
- 用JSP来实现文件下载功能的几种方式
- .net中几种不同方式的文件下载
- Asp.net 中几种文件下载方式
- 用C++运行批处理文件或是批处理命令的简单方式
- C/C++里自带提供的整数进制转换的几种方式
- java读取.properties配置文件 的几种方式
- JSP文件下载的几种方式
- 几种文件读入,文件输出的方式
- C++:string转换成int的几种方式