I have been fighting with this error for awhile now and am hoping someone can enlighten me to what the problem is. I have the text in main at the top, followed by the function that is supposed to get the info from the file, but i keep getting the same error no matter what I try, posted at the bottom of this post. Please, can anyone help.
void main()
{
srand(int(time(NULL)));
sPlayer playerAr[100];
int playerIdx = 0;
int searchItem = 0;
int numPlayers = 0;
char menuOption;
ifstream inp;
getData(inp, playerAr, numPlayers);
(........................)
void getData(ifstream& inp, sPlayer playerAr[100], int &numPlayers)
{ if(inp.open("Player Info File.txt")); // <- error appears on this line
{
while(!inp.eof());
{
for (int i = 0; i < numPlayers + 1; i++)
{
inp >> playerAr[i].playerIdx,' ';
getline(inp,playerAr[i].playerName,' ');
inp >> playerAr[i].playerGold,' ';
inp >> playerAr[i].playerHealth,' ';
inp >> playerAr[i].playerExp,' ';
numPlayers++;
}
}
inp.close();
}
}
error C2451: conditional expression of type 'void' is illegal
Expressions of type void cannot be converted to other types
It simply means that the imp.open() method do not return a value, thus void. You can't use the method for that. By looking at the refference, there should be a way to check for success. http://www.cplusplus.com/reference/iostream/ifstream/open/