0
votes
void isRegistered(std::list<User>* usersList, std::list<User>::iterator& v, std::string username, std::string password){
    std::fstream userfile = openFile("users.csv");
    readUsers(userfile, usersList); // this line 

readUsers(std::fstream file, std::list<User>* usersList) and reads whatever is in the csv file into usersList

on the second line I am getting fstream cannot be referenced -- it is a deleted function error. I can't seem to figure out why any help would be appreciated

Full error:

function "std::basic_fstream<_Elem, _Traits>::basic_fstream(const std::basic_fstream<_Elem, _Traits> &) [with _Elem=char, _Traits=std::char_traits]" (declared at line 1273 of "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\VC\TOOLS\MSVC\14.28.29910\INCLUDE\fstream") cannot be referenced -- it is a deleted functionC/C++(1776)

1
Might be helpful to include the error, verbatim. - Eljay
I can only guess but i suspect readUsers takes the fstream by copy, pass it by reference - Borgleader
What is readUsers? Does it take the stream argument by value? Streams can't be copied, you have to pass by reference. - Some programmer dude
The error message says that the std::fstream copy-constructor is deleted. As I stated before, you must pass streams by reference. - Some programmer dude

1 Answers

2
votes

As noted in comments, you cannot pass C++ streams to functions by value. The error message tells you that. To fix that, pass by reference:

readUsers(std::fstream& file, std::list* usersList);
// changed here:      ^