代码如下:
#include<iostream>
#include<fstream>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
fstream fs("test.txt");
istreambuf_iterator<char> beg(fs),end;
string data(beg,end);
FILE * f;
f= fopen("1.txt", "w");
for(int i=0; data[i]; i++) fprintf(f, "%c", data[i]);
fclose(f);
system("pause");
return 0;
}
扩展资料
数组的特点:
1、只能存储同一种数据类型的数据。
2、一旦初始化,长度固定。
3、数组中的元素与元素之间的内存地址是连续的。
注意: Object类型的数组可以存储任意类型的数据。
数组变量属引用类型,数组本身就是对象,数组中的每个元素相当于该对象的成员变量。
Java中对象是在堆中的,因此数组无论保存基本数据类型还是其他对象类型,数组对象本身是在堆中存储的。
数组的声明方式有两种(以一维数组为例)
1、type[ ] arr_name;//推荐使用这种方式)
2、type arr_name[ ]。
当C++输出到标准输出时,其本质就已经是文本输出了。
要输出到文件,可以使用ofsteam操作。
以下是一个整型数组,输出到文本文件的操作代码。
#include <iostream>