Write a program that gives and takes advice on program writing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void output_to_screen(ifstream& source_file);
void write_to_file(ofstream& target_stream);
int main()
{
ifstream fin;
ofstream fout;
fin.open("textfile1.txt");
if (fin.fail())
{
cout << "Input file opening failed.\n";
system("pause");
exit(1);
}
output_to_screen(fin);
fin.close();
fout.open("textfile1.txt");
if (fout.fail())
{
cout << "Output file opening failed.\n";
system("pause");
exit(1);
}
write_to_file(fout);
fout.close();
system("pause");
return 0;
}
void output_to_screen(ifstream& source_file)
{
using namespace std;
char next;
source_file.get(next);
while (!source_file.eof())
{
cout << next;
source_file.get(next);
}
}
void write_to_file(ofstream& target_stream)
{
using namespace std;
char next, last;
cin.get(next);
do
{
last = next;
target_stream.put(next);
cin.get(next);
} while ((next != '\n') && (last != '\n'));
}
|
And?
Topic archived. No new replies allowed.