Thank you phanalax.
So if I understand correctly, the correct syntax is like calling the streams by referring to them, not by literal file name?
We haven't covered arrays yet, and this teacher is really punitive. If I try to use anything we haven't covered in class, he will accuse me of cheating. Makes no sense to me, but that is what he does.
Ok, well... I implemented the first set of changes now I get this:
.../main.cpp:64: error: use of deleted function 'std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)'
sortmerger(in_stream1, in_stream2, out_stream);
^
So I changed it, and get this:
/home/eliza/cpp_projects/Labs/12/pg369prob7/main.cpp:64: error: could not convert '(const char*)"Sorted_numbers_1"' from 'const char*' to 'std::ifstream {aka std::basic_ifstream<char>}'
sortmerger("Sorted_numbers_1", "Sorted_numbers_2", "mergedsort");
^
I am unclear how to call the streams when invoking the function
this is now what I have, apparently the teacher put in some incorrect instructions for the assignment, so I have commented out that code
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
|
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int sortmerger(ifstream sorted_numbers_1, ifstream sorted_numbers_2, ofstream mergedsort);
//program should define a function that is called with the two input-file
//streams and the output-file stream as three arguments.
int main( )
{
ifstream in_stream1;
ifstream in_stream2;
ofstream out_stream;
in_stream1.open("Sorted_numbers_1");
in_stream2.open("Sorted_numbers_2");
out_stream.open("mergedsort");
sortmerger(in_stream1, in_stream2, out_stream);
//sortmerger("Sorted_numbers_1", in_stream2, out_stream);
return 0;
}
//int sortmerger(ifstream Sorted_numbers_1, ifstream Sorted_numbers_2, ofstream mergedsort)
int sortmerger(ifstream in_stream1, ifstream in_stream2, ofstream out_stream)
{
ifstream Sorted_numbers_1;
ifstream Sorted_numbers_2;
ofstream mergedsort;
in_stream1.open("Sorted_numbers_1");
in_stream2.open("Sorted_numbers_2");
out_stream.open("mergedsort");
if (in_stream1.fail())
{
cout << "input file open failed: Sorted_numbers_1.\n";
exit (1);
}
in_stream2.open("Sorted_numbers_2");
if (in_stream2.fail())
{
cout << "input file open failed: Sorted_numbers_2.\n";
exit (1);
}
out_stream.open("mergedsort.dat");
if (out_stream.fail( ))
{
cout << "Output file failed to open.\n";
exit (1);
}
return 0;
}
|