Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

istream operator error in MFC Application Dialog...

Status
Not open for further replies.

DrkPaladin

Programmer
May 18, 2002
33
CA
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(&quot;Save.txt&quot;, 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.
 
change sin >> SlNames[0]; to
sin << m_Name1;
sin << m_Name2;
sin << m_Name3;
sin << m_Name4;
sin << m_Name5;

Another alternative to this method is to save your variables into windows registry.
look at WriteProfileString and ReadProfileString for details.
 
Because it is a ioperator shoudln't the arrow be '>>'??? I'm loading the information from the file to the variables...

I tried what you said to do; it did get rid of the error but the information does not get loaded...

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top