-3

I already know this will get marked as duplicate, but I have already tried every solution that I could find and then my own, none of which worked. The error messages keep telling me that it expects a ")" after input, but I need it to write the info it is reading to the backup file. Any help would be appreciated.

class Data{
public:
    const unsigned static int MAXIMUM_DATA = 4100u;
const static int x = 0;
string userName[MAXIMUM_DATA] = {};
string nickName[MAXIMUM_DATA] = {};
string role[MAXIMUM_DATA] = {};
string fName[MAXIMUM_DATA] = {};
string lName[MAXIMUM_DATA] = {};
string email[MAXIMUM_DATA] = {};
friend std::istream& operator>>(std::istream& input, Data& d);
};

std::istream& operator>>(std::istream& input, Data& d){
std::istream& getline(input, d.userName);
std::istream& getline(input, d.role);
std::istream& getline(input, d.fName);
std::istream& getline(input, d.lName);
std::istream& getline(input, d.nickName);
std::istream& getline(input, d.email);
return input;
}

Data d;
    while(myfile >> d){
        database.push_back(d);
    }
  • what is that `std::istream&` in front of `getline(input, d.userName);` ?? – 463035818_is_not_an_ai Sep 26 '17 at 19:55
  • 4
    All your member variables are *arrays* of `MAXIMUM_DATA` strings. They are not strings of `MAXIMUM_DATA` characters. And you don't really *call* `getline`, it looks more like you *declare* it, with `std::istream&` as the return type. And the way you "declare" the function is invalid, leading to your build errors. Perhaps you need to [find a couple of good beginners books to read](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude Sep 26 '17 at 19:56
  • You may want convert the arrays to single variables, then have an `std::vector` of `Data`. – Thomas Matthews Sep 26 '17 at 20:03

1 Answers1

0

One of you issues is that the std::getline looks more like a function declaration. Change to:

  getline(input, /*...*/);

If you are emulating a database you may want to use a table of records.

You could define a record as:

class Data_Record
{
public:
string userName;
string nickName;
string role;
string fName;
string lName;
string email;
friend std::istream& operator>>(std::istream& input, Data_Record& dr);
};

You database can be as simple as:

std::vector<Data_Record> database;

Looks like this is what you intended to do.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154