Hello,
I have a program where I am using an object array that I declare from a class. I am trying to store information from a text file into this array. I will then be doing other items like searching the array and displaying it into another text file. I was wondering if you can look at the code below and let me know what I am doing wrong.
int main()
{
int loop=0; //Index of array
int loop2;
string line; //The line taken from the *.txt source
const int num = 6;
myClass classObj[num]; //Define an array of objects
ifstream myfile ("myTextFile.txt"); //To read from the *.txt File
if (myfile.is_open()) //Checking if the file can be opened
{
while (! myfile.eof() ) //Runs while the file is NOT at the end
{
getline (myfile,line); //Gets a single line from example.txt
classObj[loop]=line; //Saves that line in the array
loop++; //Does an increment to the variable 'loop'
}
myfile.close(); //Closes the file
}
else cout << "Unable to open file"<<endl; //Gives that sentence if the file can't be opened
for(loop2=0;loop2<=loop;loop2++) //For loop make to cout the lines stored
cout<<classObj[loop2]<<endl; //inside of the variable 'array'
return 0;
}
I am getting the following error
error: no match for 'operating=' in 'classObj[loop] = '
the text file will look something to the effect of what is listed below. There will be exactly 6 lines in the file
hi my name # is fred