c++ 文件输入输出

#include "stdafx.h"
#include "math.h"
#include "string"
#include "iostream"

#include "fstream"

using namespace std;


//导入两个字符串

ifstream fin("input.txt");
ofstream fout("output.txt");
char a[BUF_MAX];
char b[BUF_MAX];
memset(a,0,BUF_MAX*sizeof(char));
memset(b,0,BUF_MAX*sizeof(char));


fin.getline(a,BUF_MAX,'\n');
fin.getline(b,BUF_MAX,'\n');
cout << a << endl;
cout << b << endl;


//打入定长 数组

int n = 0;

double *data = NULL;

fin>>n;

data = new double[n];

for(int i = 0;i < n;i++)
{
 fin>>data[i];
 cout<<data[i]<<" ";
}
cout<<endl;



//文件输出与关闭

       fout << ret;
fin.close();
fout.close();

你可能感兴趣的:(c++ 文件输入输出)