I need to use an input(and later an output) file inside a function. I am writing this according to the textbook, and yet I recieve this error. If someone can clarify for me how I can properly use a file within a function I would be very gratefull.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int SIZE = 10;
//Function read2arrays
//Input:
// istream - input file contaning k and test gardes
// test1 and test 2 arrays for test grades
// k - number of test grades in each array
//Process:
// Inputs grades from istream into the arrays
//Output;
//
void read2arrays (istream &in, int test1[], int test2[], int &k)
in >> k;
if(k>0 && k<=SIZE)
out << "There are " << k << " test grades" <<endl;
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|20|error: expected initializer before 'in'|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|22|error: expected unqualified-id before 'if'|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|26|error: expected unqualified-id before 'else'|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|34|error: expected unqualified-id before 'for'|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|34|error: 'count' does not name a type|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|34|error: 'count' does not name a type|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|44|error: expected unqualified-id before 'return'|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp||In function 'int main()':|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|54|error: expected primary-expression before ',' token|
C:\Users\Neil Alek\Desktop\Labs\Homework 6.cpp|59|error: 'read2arrays' was not declared in this scope|
||=== Build finished: 9 errors, 0 warnings (0 minutes, 0 seconds) ===|
No gentlemen, I am trying to use 'in' in the same way as you would use infile
i.e.
infile >>variable k
in order to place a value that is inside the file into the variable k
alos, i know and fixed the int count thing, this is not a concern for me
so the question is how do i correctly use ifstream inside a function. cannot find any tutorial dealing with this, and the textbook offers only the solution that you see me using in the code.