Nick Hayes
|
Re: Reading from a file and outputting to a file
|
Nick Hayes
03/10/2011 4:16 PM
post83913
|
Re: Reading from a file and outputting to a file
We are trying to do our coding in C++.
Here is the sample code:
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <fstream>
#include <istream>
#include <ostream>
using namespace std;
int main(int argc, char *argv[]) {
std::cout << "Welcome to the QNX Momentics IDE" << std::endl;
string num;
cout<<"hello world"<<endl;
ifstream input;
ofstream output;
input.open("numbers.txt");
output.open("success.txt");
int z;
for(int i=0;i<6;i++){
input>>z;
cout<<z<<endl;
}
double one, two, ans;
one = 10.0;
two = 20.35;
ans = one*two;
cout<<ans<<" x"<<endl;
output<<ans<<" victory"<<endl;
double degree;
degree=cos(3.1459/4);
cout<<degree<<endl;
ans = pow(one,two);
cout<<ans<<" pow"<<endl;
ans = sqrt(one);
cout<<ans<<" sqrt"<<endl;
output.close();
return EXIT_SUCCESS;
}
And our file numbers.txt looks like:
1 2 5 7 8 9
And here is the console output:
Welcome to the QNX Momentics IDE
hello world
134612012
134612012
134612012
134612012
134612012
134612012
203.5 x
0.706345
2.23872e+20 pow
3.16228 sqrt
|
|
|