1 problem on one line of code

myfile >> name >> bookList[indexOfArray].getName(tempStr)

How come you are not able to do this? I want to parse the information and the put the information into an array.



We would need to see the definition of bookList, the definition of whatever type it is an array of, and, most importantly, the definition of getName().

Looking at this code, it makes NO sense.
Okay here is the code that I have
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

int main()
{
   const int arraySize = 5;
   int indexOfArray = 0;
   Employee bookList[arraySize];
   int tempPrice;//temporary stores price
   string tempStr;//temporary stores author, title
   string name;
   int identificationNumber;
   string test;






    ifstream myfile ("master8.txt");
if (myfile.is_open())
{
      while (! myfile.eof() )
       {
  //cin.ignore(255,'\n');
 //getline(myfile, tempStr, ' ');
 myfile >> name >> bookList[indexOfArray].getName(tempStr)
 myfile >> test;

 cout << bookList[indexOfArray].getName(tempStr);
           //cout << name << endl;
        //cout << name;

           identificationNumber = bookList[indexOfArray].getID(tempPrice);
               //cout << test;


           if ( indexOfArray < arraySize )//shifting array index while not exceeding array size
           {

               cout << name << " " << test << endl;
               indexOfArray++;
               //cout << indexOfArray;
           }
       }// while ( !fileIn.eof( ));
      




   for (int i = 0; i < arraySize; i++)
   {
       //cout << name << endl;
       //cout << identificationNumber << endl;
   }
myfile.close();
}
else cout << "ERROR";
return 0;
}



I was trying to set each individual word to an array element. I don't know if that is smartest idea or what?
There must be an overload for ostream& operator>>(ostream&, T) where T is the type that getName returns for that to work. Maybe you can read into a temporary string and use a setName function to update the string.
Can you show the code for Employee::getName()?
Sure the code is listed below:

1
2
3
4
string Employee::getName(string &name)
{
return name;
}
getName() returns string by value, but cin >> expects a reference to string.
Employee::getName() returns a copy of your name, a temporary object that you can assign from, but not to. You can do

1
2
3
string temp;
myfile >> temp;
bookList[indexOfArray].setName(temp);

or add a getName() which returns a reference to Employee::name. I suggest the first one.
Topic archived. No new replies allowed.