% http://www.mathworks.com/help/matlab/ref/fprintf.html
% http://www.mathworks.com/help/matlab/ref/sprintf.html
x = 0:.1:2*pi;
A = [x; sin(x)];
fileID = fopen('myfile.out','w');
fprintf(fileID,'%6.2f %12.8f\n',A);
fclose(fileID);
type exp.txt
// C
// http://www.cnblogs.com/haore147/p/3648395.html
int main()
{
double a = 0.1;
FILE *fp;
fp=fopen("myfile.out","w")
fprintf(fp,"%f\n",a);
fclose(fp);
return 0;
}
// C++
#include <fstream>
using namespace std;
int main()
{
double a = 0.1;
ofstream fp;
fp.open("myfile.out");
fp<<a<<endl;
fp.close();
return 0;
}
! Fortran
program sample
implicit none
real(kind=8), parameter:: a = 0.1
open(unit = 10, file='myfile.out')
write(10,1000) a
1000 format(f20.10)
close(10)
end program sample
Write data to text file in C/C++, Fortran, and Matlab
于 2018-06-16 14:04:05 首次发布