Reading strings from file into array errors.

Im trying to write a code to read hours and names from a .txt file for employees hours.

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
  #include <iostream>
#include <fstream>
using namespace std;

int main()
{
	const int NUM_EMPLOYEES = 8;
	string name[NUM_EMPLOYEES];
	int hours[NUM_EMPLOYEES];
	int count;
	ifstream fin;

	fin.open("hours.txt");
	if (!fin)
		cout << "Error opening file." << endl;
	else
	{
		for (count = 0; count < NUM_EMPLOYEES; count++)
		{
			//Error here, the '>>' before name[count] gives the message no operator ">>" matches these operands
			fin >> name[count];
			fin >> hours[count];
		}
		fin.close()


.txt file

Bob 35
Sally 40
Steve 32
Brian 18
Marcus 25
Esteban 40
Jessica 35
Peter 30

Would anyone know why the fin >> name[count] is providing the error?
fin >> hours[count] works fine but not name
Try adding the header for std::string
#include <string>
Ah yes, the ever important string header...silly me. Thanks!
Topic archived. No new replies allowed.