Final Answer:
The `readLikes` function, a standalone function, reads data from a specified file, creating User objects for each line, and populates the provided array of User objects with their respective likes for posts.
Step-by-step explanation:
The `readLikes` function begins by checking if the array is already full (`num_users_stored` equals `users_arr_size`). If so, it returns -2, indicating that no additional users can be added. Next, it attempts to open the specified file using `ifstream` and checks if the file opens successfully. If the file cannot be opened, it returns -1, signaling an error.
Assuming the file opens successfully, the function proceeds to read data from the file using `getline`. For each line, it creates a new User object, extracts the username and sequence of likes using the `split` function, and populates the User object accordingly. The function then appends this User object to the `users` array. This process continues until the array is full or the file is fully processed.
The function returns the total number of users in the system, considering both the existing users in the array (`num_users_stored`) and the newly added users. The implementation ensures the array doesn't exceed its capacity. This modular function allows for efficient reading and incorporation of user data from the file into the existing array.