Click here to Skip to main content
15,914,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WSAAsyncSelect and FD_WRITE Pin
Moak9-Jan-10 12:00
Moak9-Jan-10 12:00 
QuestionHow to check if a tree is AVL tree? Pin
Cowork8-Jan-10 22:17
Cowork8-Jan-10 22:17 
QuestionRe: How to check if a tree is AVL tree? Pin
CPallini9-Jan-10 4:42
mveCPallini9-Jan-10 4:42 
AnswerRe: How to check if a tree is AVL tree? Pin
Cowork9-Jan-10 13:50
Cowork9-Jan-10 13:50 
GeneralRe: How to check if a tree is AVL tree? Pin
CPallini9-Jan-10 22:50
mveCPallini9-Jan-10 22:50 
AnswerRe: How to check if a tree is AVL tree? Pin
Saurabh.Garg9-Jan-10 14:30
Saurabh.Garg9-Jan-10 14:30 
Questionregular expression library for win32 api c or c++ Pin
Jayapal Chandran8-Jan-10 7:55
Jayapal Chandran8-Jan-10 7:55 
AnswerRe: regular expression library for win32 api c or c++ Pin
LunaticFringe8-Jan-10 8:57
LunaticFringe8-Jan-10 8:57 
GeneralRe: regular expression library for win32 api c or c++ Pin
Jayapal Chandran9-Jan-10 5:37
Jayapal Chandran9-Jan-10 5:37 
GeneralRe: regular expression library for win32 api c or c++ Pin
LunaticFringe9-Jan-10 11:56
LunaticFringe9-Jan-10 11:56 
GeneralRe: regular expression library for win32 api c or c++ Pin
Jayapal Chandran10-Jan-10 8:14
Jayapal Chandran10-Jan-10 8:14 
AnswerRe: regular expression library for win32 api c or c++ Pin
Graham Shanks8-Jan-10 10:39
Graham Shanks8-Jan-10 10:39 
AnswerRe: regular expression library for win32 api c or c++ Pin
Nemanja Trifunovic8-Jan-10 12:07
Nemanja Trifunovic8-Jan-10 12:07 
GeneralRe: regular expression library for win32 api c or c++ Pin
Jayapal Chandran9-Jan-10 5:39
Jayapal Chandran9-Jan-10 5:39 
QuestionQuestion about reading and writing to a file Pin
amichai228-Jan-10 6:25
amichai228-Jan-10 6:25 
I am trying to write a triple vector to a file and then read the file back into the triple vector. When I try to read the file back after its been saved the first fifty values come out correct but the rest of the values are garbage. I'd be really appreciative if someone could help me out here. Thanks a lot!

File declaration:

fstream memory_file("C:\\Users\\Amichai\\Pictures\\output.txt", ios::in | ios::out);


The write function:

void save_training_data(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
 {
   int sizeI = training_data.size();
   memory_file.write((const char *)&sizeI, sizeof(int));
   for (int i=0; i < sizeI; i++)
   {
       int sizeJ = training_data[i].size();
       memory_file.write((const char *)&sizeJ, sizeof(int));
       for (int j=0; j < sizeJ; j++) 
       {
           int sizeK = training_data[i][j].size();
           memory_file.write((const char *)&sizeK, sizeof(int));
           for (int k = 0; k < sizeK; k++)
           {
               int temp;
               temp = (int)training_data[i][j][k];
               memory_file.write((const char *)&temp, sizeof(int));
           }
       }
   } 
 }


The read function:

void upload_memory(fstream &memory_file, vector<vector<vector<long double> > > &training_data)
{
     memory_file.seekg(ios::beg);
     int temp=0;
     int sizeK, sizeJ, sizeI; 
     memory_file.read((char*)&sizeI, sizeof(int));
     training_data.resize(sizeI);
     for (int i=0; i < sizeI; i++)
     {
           memory_file.read((char*)&sizeJ, sizeof(int));
           training_data[i].resize(sizeJ);           
           for (int j=0; j < sizeJ; j++)
           {
               memory_file.read((char*)&sizeK, sizeof(int));
               training_data[i][j].resize(sizeK);
               for (int k = 0; k < sizeK; k++)
               {
                    memory_file.read((char*)&temp, sizeof(int));
                    training_data[i][j][k]=temp;
               }
           }
     } 
}


Thanks again,
Amichai
AnswerRe: Question about reading and writing to a file Pin
amichai228-Jan-10 6:28
amichai228-Jan-10 6:28 
GeneralRe: Question about reading and writing to a file Pin
Nelek8-Jan-10 6:38
protectorNelek8-Jan-10 6:38 
Questionstring array Pin
CODEPC8-Jan-10 5:08
CODEPC8-Jan-10 5:08 
AnswerRe: string array Pin
Richard MacCutchan8-Jan-10 5:28
mveRichard MacCutchan8-Jan-10 5:28 
AnswerRe: string array Pin
Rajesh R Subramanian8-Jan-10 6:07
professionalRajesh R Subramanian8-Jan-10 6:07 
GeneralRe: string array Pin
Cedric Moonen8-Jan-10 7:35
Cedric Moonen8-Jan-10 7:35 
GeneralRe: string array Pin
Rajesh R Subramanian8-Jan-10 7:51
professionalRajesh R Subramanian8-Jan-10 7:51 
GeneralRe: string array Pin
Cedric Moonen8-Jan-10 8:06
Cedric Moonen8-Jan-10 8:06 
GeneralRe: string array Pin
Richard MacCutchan8-Jan-10 8:59
mveRichard MacCutchan8-Jan-10 8:59 
JokeRe: string array Pin
CPallini9-Jan-10 4:56
mveCPallini9-Jan-10 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.