class Player
{
public:
struct Account
{
int Position;
string Name;
int Score;
string Date;
int Level;
};
vector<Account> User;
};
void Player::LoadPlayerStats()
{
// Push back User a bunch of times
// Populate the elements of each struct
// OUTPUT GIVES ME CORRECT VALUES
}
string Player::GetPlayerStats(int index)
{
// OUTPUT GIVES ME NOTHING
return User[index].Name;
}
int main()
{
Player player;
player.LoadPlayerStats();
string str=player.GetPlayerStats(0);
// OUTPUT GIVES ME NOTHING
return 0;
}
I also try to access it directly like so:
1 2 3 4 5 6
int main()
{
Player player;
player.LoadPlayerStats();
cout<<player.User[0].Name; // Nothing outputs
}
Add check after loop and before sort: if( !File.eof() ) std::cerr << "an error occured reading file";
Check if it is output or not. Also you need to call clear on file stream before opening if you use persistent file and do not use C++11.
Can you post a minimal compiling example reproducing your problem? http://sscce.org/