332 Introduction to C++ Programming and Graphics
Matlab C++
#include<iostream>
a=input(”); cin>>a;
b=input(’Please enter b:’) cout<<“Please enter b:\n”;
cin>>b;
disp(a) cout<<a<<endl;
fprintf(’%10.5f\n’,a) #include<iomanip>
cout<<setprecision(5)
<<setw(10); cout<<a
<<endl;
name = fopen(’input.dat’); #include<iostream>
ifstream name;
name.open(“input.dat”);
name = fopen(’input.dat’,’wt’) #include<fstream>
ifstream name(“input.dat”);
fprintf(name, ’%f %f %f\n’,a,b,c) name>>a>>b>>c
>>endl;
fprintf(name, ’%f’,a(i,j)) name>>a[i][j];
fclose(name) name.close();
name=fopen(’output.dat’,’wt’); #include<fstream>
ofstream name;
name.open(“output.dat”);
#include<fstream>
name=fopen(’output.dat’,’wt’); ofstream name(“output.dat”);
fprintf(name,’%f’,a) name<<a;
fclose(name) name.close();
Table C.5 EquivalentMatlab/C++ structures and calls regarding input and
output (I/O). The#include statements are placed at the top of the file
containing the C++ code.iostreamcontains the header files of the standard
input/output (keyboard/monitor) stream.fstreamcontains the header files
of thefilestream.