Re: Large text files and searching text
Both suggested forms of fopen also give errors. See below.
None of the methods in the helpfile seem to allow filename to be a CString?
void CAdelphiDlg::OnLbnSelchangeList1()
{
int nSelect;
nSelect = c_List1.GetCurSel();
CString cSelect;
c_List1.GetText( nSelect, cSelect );
CString JobFile;
JobFile = _T("C:\\AdelphiCP\\Cip3\\"); //re-apply main part of
path to files
JobFile += cSelect; //add filename selected
JobFile += _T(".cip"); //re-apply file extension
CString mess;
mess.Format(_T("Would you like to load \"%s\" as top ?"), cSelect);
int a = AfxMessageBox(mess, MB_ICONQUESTION | MB_YESNO);
if(a != IDYES)
return;
FILE *in;
in = _tfopen(JobFile, "rb");
error C2664: '_wfopen' : cannot convert parameter 2 from 'const char [3]' to
'const wchar_t *'
in = _wfopen(JobFile, "rb");
error C2664: '_wfopen' : cannot convert parameter 2 from 'const char [3]' to
'const wchar_t *'
}
==================================================================================
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:%23d27GAfqIHA.3680@TK2MSFTNGP05.phx.gbl...
Kahlua wrote:
This is the way I have done it in the past with no problems.
CString JobFile;
JobFile = _T("C:\\AdelphiCP\\Cip3\\"); //re-apply main part of
path to files
JobFile += cSelect; //add filename selected
in OnLbnSelchangeList1()
JobFile += _T(".cip"); //re-apply file
extension
CString mess;
mess.Format(_T("Would you like to load \"%s\" as top ?"), cSelect);
int a = AfxMessageBox(mess, MB_ICONQUESTION | MB_YESNO);
if(a != IDYES)
return;
FILE*in;
in = fopen(JobFile, "rb");
fseek(in, 0, SEEK_END); //Move File Pointer to
EOF
int lth = ftell(in); //Get position of FP
fseek(in, 0, SEEK_SET); //Move FP back to
beginning of file
edi = new TCHAR[lth]; //create new string of
filelength
fread (edi, lth, 1, in); //read into the new
string
fclose (in);
Now in VC++2005 it generates an error @ in=fopen(JobFile, "rb");
error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
'const char *'
Kahlua:
MFC and the C/C++ do not change completely between one version and
another, and an approach that worked in VC6 can almost always be made to
work in later versions. There is no need to rewrite your code.
Here the problem is that a VS2005 project is Unicode by default, so that
CString uses 16-bit (wide) characters. If you look up fopen in the help,
you will also find _wfopen (or _tfopen) which is what you need to open
files with Unicode file names.
[Alternatively, but not recommended, you could change your project to ANSI
(8-bit) build.]
You might also consider the safe versions fopen_s and _wfopen_s (or
_tfopen_s).
--
David Wilkinson
Visual C++ MVP