Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
~$ echo "1 2 3 4" > in.txt ~$ ls ~$ cat in.txtYou will see a new file
in.txt has been created, which contains
four numbers (i.e., 1, 2, 3, and 4).
echo command works like cout in the terminal (i.e.,
output a string to the terminal), and the redirection operator >
redirects (i.e., saves) the terminal output to a file.
in.txt and write them to
out.txt.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin("in.txt");
ofstream fout("out.txt");
int n;
while( fin ) {
fin >> n;
fout << n << " ";
}
fout << endl;
return 0;
}
hw14_1.cpp. Then compile and run the program as follows:
~$ g++ hw14_1.cpp ~$ ./a.out ~$ cat out.txtWrite the result of the last
cat command (i.e., the contents of out.txt).
3 4 23 788 12 -6 0 2 -337 -8923 25656 -89 0 1that contains a table of integers in unformatted text, and writes out a file
output.html that
shows the same table in html, which looks like this
<table border=2> <tr><td>23</td><td>788</td><td>12</td><td>-6</td></tr> <tr><td>0</td><td>2</td><td>-337</td><td>-8923</td></tr> <tr><td>25656</td><td>-89</td><td>0</td><td>1</td></tr> </table> |
and renders like this |
|
You must assume:
input.txt.
output.html produced by your program with this input file. The result should look like:| 23 | 788 | 12 | -6 | 7 |
| 0 | 2 | -337 | -8923 | 7 |
| 25656 | -89 | 0 | 1 | 7 |
| 8 | 67 | 14 | -2 | 0 |