|
-
November 12th, 2009, 03:22 AM
#16
Re: Problem on using VC++ 2008
Sorry I will explain it again.....
Code:
#include<ifstream>;
using namespace std;
CStringList parList;
fstream sourcefile;
CFileDialog FileDlg(FALSE, _T("txt"),_T("ParameterFile"), OFN_CREATEPROMPT|OFN_HIDEREADONLY |
OFN_SHOWHELP|OFN_OVERWRITEPROMPT|OFN_LONGNAMES, _T("Save the file as(*.txt)|*.txt||"));
if (FileDlg.DoModal() == IDCANCEL)
return;
_TCHAR sFileName[MAX_PATH];
BeginWaitCursor();
UpdateData(true);
_tcscpy(sFileName, FileDlg.GetFileName());
sourcefile.open(sFileName,ios:out);
if(!sourcefile.is_open())
AfxMessageBox(_T("file for saving not opened"));
else
for (POSITION Pos1 = parList.GetHeadPosition(); Pos1 != NULL);
sourcefile<< (LPCTSTR)parList.GetNext(Pos1)+_T('\n');
sourcefile.close();
This is my code I've written for the function to save the data to a file.
The CStringList parList contains the datas(Which are enthered by users) from a ListBox(this has done on another function
already). I am trying to load it on the fstream sourcefile.
Code:
parList.GetNext(pos1)
returns the exact value entered.But it is not loading to the file.
When am opening the file,it has some Hex values there(hope, these r address).
How to fix it???
-
November 12th, 2009, 07:14 AM
#17
Re: Problem on using VC++ 2008
You have the following code ... does it even compiile ?
Code:
for (POSITION Pos1 = parList.GetHeadPosition(); Pos1 != NULL);
sourcefile<< (LPCTSTR)parList.GetNext(Pos1)+_T('\n');
-
November 12th, 2009, 10:48 AM
#18
Re: Problem on using VC++ 2008
Ya.. I've compiled it.....
This only returns the file with some unknown data..
-
November 12th, 2009, 11:15 AM
#19
Re: Problem on using VC++ 2008
Is this a UNICODE build? Does the CString member of CStringList evaluate to CStringA or CStringW? Check with the debugger if you have to.
-
November 12th, 2009, 11:16 AM
#20
Re: Problem on using VC++ 2008
1) I do not think that it should compile
2) Do you really want a semi-colon at the end of the for statement.
Last edited by Philip Nicoletti; November 12th, 2009 at 11:18 AM.
-
November 12th, 2009, 11:18 AM
#21
Re: Problem on using VC++ 2008
 Originally Posted by Philip Nicoletti
3) Why do you have a semi-colon at the end of the for statement?
Missed that. Good catch!
It should compile, but the loop ends at the semicolon.
Pos is normally incremented as part of GetNext().
Edit: It's missing a semicolon in the for(; loop so it should NOT compile. I stand corrected.
Last edited by hoxsiew; November 12th, 2009 at 11:20 AM.
-
November 12th, 2009, 11:30 AM
#22
Re: Problem on using VC++ 2008
Sorry... That was my mistake while copying not in compilation...
I was copying it from the already posted codes..so there some smileys came n I just cleared without much care..
The code I've copied is
Code:
for(Position Pos1=ParList.GetHeadPosition();Pos1!=NULL;)
And it has compiled without any error..
I still conusing that my error is in part of fstream..
Shd I take any else precautions b4 using fstream??
-
November 12th, 2009, 11:36 AM
#23
Re: Problem on using VC++ 2008
You need to determine what kind of string (wide or multi-byte) you are getting form you CStringList. Just casting the return value to LPCTSTR won't cut it if the fundamental type is wrong (wchar_t * v. char *).
-
November 12th, 2009, 11:53 AM
#24
Re: Problem on using VC++ 2008
It is CString I hope..
Sorry that, am not @ my work place nw...and I can't access internet from ther..
So can't confirm nw.. Bt the return value is a CString only. I've verified it by returning on CString..
done as
Code:
CString ss;
ss=parList.GetNext();
::AfxMessageBox(ss);
and it get's the exact data, which i needed..
??
-
November 12th, 2009, 12:09 PM
#25
Re: Problem on using VC++ 2008
"CString" is a macro that can evaluate to either CStringA or CStringW depending on whether you are building a UNICODE app (whether _UNICODE is defined) or not.
-
November 12th, 2009, 12:19 PM
#26
Re: Problem on using VC++ 2008
 Originally Posted by arunkr6
It is CString I hope..
Sorry that, am not @ my work place nw...and I can't access internet from ther..
Not good... 
You was many times asked whether your current build is UNICODE or ANSI. You haven't answer yet...
Note that if it is a UNICODE one then you must use wfstream instead of fstream
Victor Nijegorodov
-
November 12th, 2009, 12:42 PM
#27
Re: Problem on using VC++ 2008
I havn't defined it as UNICODE.
-
November 12th, 2009, 12:58 PM
#28
Re: Problem on using VC++ 2008
Apps built by the AppWizard should default to UNICODE in VS2005 and later.
-
November 12th, 2009, 01:14 PM
#29
Re: Problem on using VC++ 2008
So what should I do further??
I need ASCI values.
So I have to change as wfstream right??
lemme compile it n get u the response...thank u...
Last edited by arunkr6; November 12th, 2009 at 01:19 PM.
-
November 14th, 2009, 03:49 AM
#30
Re: Problem on using VC++ 2008
thank u..
it got worked.. i jus changed 2 wfstream.... got the problems,,
thank u..all
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|