Jump to content
  • Advertisement
Sign in to follow this  
TLAK1001

Can't load vector

This topic is 4416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a server/client application where the server must load a list of all clients plus their actual name and password. A currently seperate program writes the data as follows:
 cout<<"Saving..."<<endl;
    ofstream nameFout(NAMEFILE,ios::binary); //Write the name vector
    nameFout.write((char*)(&numOfClients),sizeof(numOfClients)); /*Server needs
                                     to know how many clients are in the list*/
    vectorSize=sizeof(userNames);
    nameFout.write((char*)(&vectorSize),sizeof(vectorSize));
    nameFout.write((char*)(&userNames),vectorSize);
    nameFout.close();
    
    ofstream litFout(LITNAMEFILE,ios::binary); //Write the lit name vector
    vectorSize=sizeof(litNames);
    litFout.write((char*)(&vectorSize),sizeof(vectorSize));
    litFout.write((char*)(&litNames),vectorSize);
    litFout.close();
    
    ofstream passFout(PASSFILE,ios::binary); //Write the password vector
    vectorSize=sizeof(passwords);
    passFout.write((char*)(&vectorSize),sizeof(vectorSize));
    passFout.write((char*)(&passwords),vectorSize);
    passFout.close();

When the server accesses the saved data as follows:
ifstream nameFin(NAMEFILE,ios::binary); //Load the name vector
    nameFin.read((char*)(&numOfClients),sizeof(numOfClients)); /*numOfClients is
                                                           included in this file*/
    nameFin.read((char*)(&vectorSize),sizeof(vectorSize));
    nameFin.read((char*)(&userNames),vectorSize);
    nameFin.close();
    
    ifstream litNameFin(LITNAMEFILE,ios::binary); //Load the litNames vector
    litNameFin.read((char*)(&vectorSize),sizeof(vectorSize));
    litNameFin.read((char*)(&litNames),vectorSize);
    litNameFin.close();
    
    ifstream passFin(PASSFILE,ios::binary); //Load the passwords
    passFin.read((char*)(&vectorSize),sizeof(vectorSize));
    passFin.read((char*)(&passwords),vectorSize);
    passFin.close();
    
    cout<<"DONE"<<endl;

it fails to properly load the vectors. I get an access violation when I do cout<<vector[0]<<endl; What's going on?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!