DrkPaladin
Programmer
I was able to save to a Binary .txt file by "overloading the operator"...This is in a MFC Application Dialog Based
But when I want to load the informaton back into the Variables I get an error in the istream operator:
************************************************************
error C2678: binary '>>' : no operator defined which
takes a left-hand operand of type 'class fstream' (or
there is no acceptable conversion)
************************************************************
#include <fstream.h>
#include <iostream.h>
//*****Structure*****
struct SSlotNames{CString SName1;
CString SName2;
CString SName3;
CString SName4;
CString SName5;};
//*****istream Operator*****
istream& operator >> (fstream& str_Sin, struct SSlotNames& SlNames)
{
str_Sin >> SlNames.SName1;
str_Sin >> SlNames.SName2;
str_Sin >> SlNames.SName3;
str_Sin >> SlNames.SName4;
str_Sin >> SlNames.SName5;
return (str_Sin);
};
//*****OnLoad Function*****
void CSavingDlg::LoadNames()
{
UpdateData();
//***Structures***
struct SSlotNames SlNames[1];
//***Set Mode***
int Sin_mode = (ios::in|ios::binary);
//***Open file***
fstream sin("Save.txt", Sin_mode);
sin >> SlNames[0];
//***Set Slot Names***
m_Name1 = SlNames[0].SName1;
m_Name2 = SlNames[0].SName2;
m_Name3 = SlNames[0].SName3;
m_Name4 = SlNames[0].SName4;
m_Name5 = SlNames[0].SName5;
UpdateData(FALSE);
}
////////////////////////////////////////////////////////////
How would I fix this error or is there a more simpler way to save and load Variable Information to a File???
Please Help Me.
Thanks.
But when I want to load the informaton back into the Variables I get an error in the istream operator:
************************************************************
error C2678: binary '>>' : no operator defined which
takes a left-hand operand of type 'class fstream' (or
there is no acceptable conversion)
************************************************************
#include <fstream.h>
#include <iostream.h>
//*****Structure*****
struct SSlotNames{CString SName1;
CString SName2;
CString SName3;
CString SName4;
CString SName5;};
//*****istream Operator*****
istream& operator >> (fstream& str_Sin, struct SSlotNames& SlNames)
{
str_Sin >> SlNames.SName1;
str_Sin >> SlNames.SName2;
str_Sin >> SlNames.SName3;
str_Sin >> SlNames.SName4;
str_Sin >> SlNames.SName5;
return (str_Sin);
};
//*****OnLoad Function*****
void CSavingDlg::LoadNames()
{
UpdateData();
//***Structures***
struct SSlotNames SlNames[1];
//***Set Mode***
int Sin_mode = (ios::in|ios::binary);
//***Open file***
fstream sin("Save.txt", Sin_mode);
sin >> SlNames[0];
//***Set Slot Names***
m_Name1 = SlNames[0].SName1;
m_Name2 = SlNames[0].SName2;
m_Name3 = SlNames[0].SName3;
m_Name4 = SlNames[0].SName4;
m_Name5 = SlNames[0].SName5;
UpdateData(FALSE);
}
////////////////////////////////////////////////////////////
How would I fix this error or is there a more simpler way to save and load Variable Information to a File???
Please Help Me.
Thanks.