C2678

1
2
3
4
5
6
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// function definitions
bool loadList(int list[], int& size)
{
	size = 0;
	int count = 0;
	list[MAX_SIZE];
	string myFile;
	ifstream inFile;

	cout << "Enter file name: ";
		cin >> myFile;

		inFile.open(myFile);

		inFile >> list;
		while (inFile)
		{
			list[count] = size;
			count = count + 1;
			inFile >> list;
		}
		
		return list;
}


The point of this function is to open the file and load the values inside to "list" for use elsewhere. The problem occurs at inFile >> list; (lines 15 and 20). I've read elsewhere about overloading the expression, but I don't exactly know what that means. Any help is appreciated

edit:
1
2
3
4
5
6
void displayScores (int list[], int size)
{
	for (int index = 0; index < size; index++)
		cout << list[index] << " ";
	cout << endl;
}

Is what I will be using to display from the "list"
Last edited on
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
#include <iostream>
#include <fstream>
#include <string>

const int MAX_SIZE = 100 ;

bool loadList( std::string file_name, int list[MAX_SIZE], int& size )
{
    size = 0;
    std::ifstream inFile(file_name);

    int number ;
    while( size < MAX_SIZE && inFile >> number )
    {
        list[size] = number ;
        ++size ;
    }

    return size != 0 ;
}

int main()
{
    int list[MAX_SIZE] ;

    std::string myFile ;
    std::cout << "Enter file name: ";
    std::cin >> myFile ;

    int actual_size = 0 ;
    loadList( myFile, list, actual_size ) ;

    displayScores( list, actual_size  ) ;
}
Topic archived. No new replies allowed.