Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help with three visual studio errors - C++ errors occuring when trying to build solution
    text
    copied!<p>I get the following errors when I try to build this project:</p> <pre><code>error C2182: 'read_data':illegal use of type 'void' error C2078: too many initializers errors c2440: 'initializing': cannot convert from 'std::ofstream' to int </code></pre> <p>All of the above seem to be pointing to my function call on line 72, which is this line: void read_data(finput, foutput);</p> <p>I've looked up these error codes on the MSDN site but wasn't able to use the description to deduce what might be wrong.</p> <p>Any ideas/tips are appreciated.</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;iomanip&gt; #include &lt;string&gt; using namespace std; void read_data(ifstream&amp; finput, ofstream&amp; foutput); //PRE: The address of the ifstream &amp; ofstream objects is passed to the function //POST: The data values are read in until the end of the file is reached void print_data(ofstream&amp; foutput, string fname, string lname, int largest, int smallest); //PRE: The address of the ofstream object and the values of fname, lname and largest and smallest integer // in each row is passed to the function //POST: The values are outpur to the file with formatting int max(int num1, int num2, int num3, int num4); //PRE: Four integer values are passed to the function //POST: The largest of the four integer values is returned int min(int num1, int num2, int num3, int num4); //PRE: Four integer values are passed to the function //POST: The smallest of the four integer values is returned int main() { //Declare the filestream objects ifstream finput; ofstream foutput; //Attempt to open the input &amp; output files //In each case, print an error message and quit if they fail to open finput.open("program4_input.txt"); if (finput.fail()) { cout &lt;&lt;"The input file failed to open!" &lt;&lt; endl; return exit(1); } foutput.open("output.txt"); if (foutput.fail()) { cout &lt;&lt;"The output file failed to open!" &lt;&lt; endl; return exit(2); } void read_data(finput, foutput); return 0; } //Function definitions void read_data(ifstream&amp; finput, ofstream&amp; foutput) { string fname, lname; int num1, num2, num3, num4, largest, smallest; while(finput &gt;&gt; fname) { finput &gt;&gt; lname &gt;&gt; num1 &gt;&gt; num2 &gt;&gt; num3 &gt;&gt; num4; largest = max(num1, num2, num3, num4); smallest = min(num1, num2, num3, num4); print_data(foutput, fname, lname, largest, smallest); } } void print_data(ofstream&amp; foutput, string fname, string lname, int largest, int smallest) { foutput &lt;&lt; setw(15) &lt;&lt; fname &lt;&lt; setw(15) &lt;&lt; lname &lt;&lt; setw(10) &lt;&lt; largest &lt;&lt; setw(10) &lt;&lt; smallest &lt;&lt; endl; } int max(int num1, int num2, int num3, int num4) { int lnum, lnum1, lnum2; if (num1 &gt; num2) { lnum1 = num1; } else lnum1 = num2; if (num3 &gt; num4) { lnum2 = num3; } else lnum2 = num4; if (lnum1 &gt; lnum2) { lnum = lnum1; } else lnum = lnum2; return lnum; } int min(int num1, int num2, int num3, int num4) { int snum, snum1, snum2; if (num1 &lt; num2) { snum1 = num1; } else snum1 = num2; if (num3 &gt; num4) { snum2 = num3; } else snum2 = num4; if (snum1 &gt; snum2) { snum = snum1; } else snum = snum2; return snum; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload