With functions and arrays

If I have a program and I need 'Array A' to read in values from an infile, how would I make that into a function?

And also 'ArrayB' needs to be setup with 25 random numbers from 1 - 100(no zeros). I haven't messed with the random numbers before

But I also can only have ONE function that prints only one array. So i'd have to call it multiple times within my code.

Something like this would read into an array.

1
2
3
4
5
6
7
void function_to_read_into_an_array(type* array, int size,  istream& infile )
{
  for (int i = 0 ; i < size; i++)
  {
    infile >> array[i];
  }
}


Now that I've said that, don't use arrays. Use vectors. Arrays are not for beginners. Vectors are.
Last edited on
http://www.cplusplus.com/reference/random/uniform_int_distribution/

and a printer just looks *exactly* like the above except cout << instead of file >>
I understand the prototype and the for statement. But i'm confused on how it works. Each time I build my code I receive an error stating "no match for operator>>".



1
2
3
4
5
6
7
int ArrayA(ofstream& outF, ifstream& inF, int x, int n)
{
	inF.open("numbers2.in");
	for(x=0;x<n;x++)
		inF>>ArrayA[x];
	return ArrayA[];
}


ArrayA[x];

What is this meant to be? It makes no sense. ArrayA is the name of your function. Where's your array?
If I have a program

It would be helpful if you posted as much of the code as needed to get a compile-able example. Posting very short code snippets only could be hiding where the real problems are in other parts of your code you don't let us see.
Furry Guy, I have posted the full code, unsure how to show you a direct link. But it's on the thread, or if you click my name it should show you my latest thread post, I believe.

Repeater, I am very green and unsure of myself when it comes to coding. My professor lectures and writes snips of code on the board and expects us to know everything. Once I get home with my assignments and sit down with them, that's when all my questions arise. So please, bare with me as I truly don't understand waht I am doing within my codes.
Jonin, I appreciate the advice, as of right now my professor wants us to use Arrays and read from a file and print to a file. No more cout or cin is allowed in our codes, we must use functions for everything also. Which causes more headaches, as i'm thinking its difficult for me to use functions and arrays and keep everything in order.
Registered users can post here. Sign in or register to post.