c/c++輸出重定向的方法
更新時間:2013年03月14日 10:40:54 作者:
c/c++輸出重定向的方法,需要的朋友可以參考一下
c:
復(fù)制代碼 代碼如下:
#include<stdio.h>
int main(int argc,char* argv[])
{
char test[]="c語言輸出重定向測試";
int i;
if (freopen("F:\\雜文件\\test.txt", "w", stdout)==NULL)
fprintf(stderr, "重定向錯誤!無法輸出到文本\n");
for(i=0;i<=9;i++)
{
printf("%s\n%d\n",test,i);
}
fclose(stdout);
return 0;
}
從上面可以看出轉(zhuǎn)義字符是可以寫入文件的。
c++:
復(fù)制代碼 代碼如下:
#include<fstream>
#include <iostream>
using namespace std;
int main()
{
ofstream log("F:\\雜文件\\test2.txt");
streambuf * oldbuf = cout.rdbuf(log.rdbuf());
cout << "c語言輸出重定向測試"<<endl<<"123456" ;
return 0;
}
相關(guān)文章
簡單了解C語言中直接插入排序與直接選擇排序?qū)崿F(xiàn)
這篇文章主要介紹了C語言中直接插入排序與直接選擇排序?qū)崿F(xiàn),插入排序的基本操作就是將一個數(shù)據(jù)插入到已經(jīng)排好序的有序數(shù)據(jù)中,從而得到一個新的、個數(shù)加一的有序數(shù)據(jù),需要的朋友可以參考下2016-03-03

