D
David Briggs
I am using MFC VC++ 6.0
and I have a simple class 'Data' with a CString member var. Name.
I added operator << and >> as:
#include <istream>
#include <ostream>
#include <fstream>
std:stream& operator<<(std:stream& fs, const Data& x )
{
fs << x.Name;
return fs;
};
std::istream& operator>>( std::istream& fs, Data& x )
{
LPTSTR p = x.Name.GetBuffer( 10 );
fs >> p;
x.Name.ReleaseBuffer(-1);
return fs;
};
Now when I go to use this in my dialog:
void CIotestDlg::OnFileOpen()
{
CFileDialog Dlg(TRUE, "txt", "*.txt");
if(IDOK == Dlg.DoModal())
{
std::ifstream fs;
fs.open(Dlg.GetPathName());
operator>>(fs, myData);
}
UpdateData( FALSE );
}
I get this error. (I also tried just fs >> myData
error C2665: '>>' : none of the 22 overloads can convert parameter 1 from
type 'class std::basic_ifstream<char,struct std::char_traits<char> >'
I don't know how to fix this.
and I have a simple class 'Data' with a CString member var. Name.
I added operator << and >> as:
#include <istream>
#include <ostream>
#include <fstream>
std:stream& operator<<(std:stream& fs, const Data& x )
{
fs << x.Name;
return fs;
};
std::istream& operator>>( std::istream& fs, Data& x )
{
LPTSTR p = x.Name.GetBuffer( 10 );
fs >> p;
x.Name.ReleaseBuffer(-1);
return fs;
};
Now when I go to use this in my dialog:
void CIotestDlg::OnFileOpen()
{
CFileDialog Dlg(TRUE, "txt", "*.txt");
if(IDOK == Dlg.DoModal())
{
std::ifstream fs;
fs.open(Dlg.GetPathName());
operator>>(fs, myData);
}
UpdateData( FALSE );
}
I get this error. (I also tried just fs >> myData
error C2665: '>>' : none of the 22 overloads can convert parameter 1 from
type 'class std::basic_ifstream<char,struct std::char_traits<char> >'
I don't know how to fix this.