-
November 9th, 2009, 10:56 AM
#1
Problem on using VC++ 2008
I have worked on VC++6.0,
Now first time, am on VC++.Net 2008 platform....
Here I want to Save some datas of a Listbox to a file... So I have tried the following code
CFileDialog FileDialog(FALSE, "txt","downloader", OFN_CREATEPROMPT|OFN_HIDEREADONLY |
OFN_SHOWHELP|OFN_OVERWRITEPROMPT|OFN_LONGNAMES, "Save the file as (*.txt)|*.txt||");
if (FileDialog.DoModal() == IDCANCEL)
return;
char sFileName[255];
BeginWaitCursor();
UpdateData(true);
strcpy(sFileName, FileDialog.GetFileName());
sourceFile.open(sFileName,ios:ut);
if(!sourceFile.is_open())
AfxMessageBox("file for saving not opened");
else
for (POSITION Pos1 = pFrame->Batch_boardList.GetHeadPosition(); Pos1 != NULL
sourceFile <<pFrame->Batch_boardList.GetNext(Pos1)+'\n';
sourceFile.close();
This was the code I have used in VC++ 6.0,
On the same routine, I've tried it on 2008... But the CFileDialog class itself creates some errors.. n solved.(without error)
Here I can't copy "strcpy(sFileName, FileDialog.GetFileName());"
The error noted as The Parameter 2 cannot convert from CString to char*..
Plz explain how it is so?? and how can I solve it??
-
November 9th, 2009, 11:24 AM
#2
Re: Problem on using VC++ 2008
Probably a UNICODE - MCBS issue. Try:
Code:
CFileDialog FileDialog(FALSE, "txt","downloader", OFN_CREATEPROMPT|OFN_HIDEREADONLY |
OFN_SHOWHELP|OFN_OVERWRITEPROMPT|OFN_LONGNAMES, "Save the file as (*.txt)|*.txt||");
if (FileDialog.DoModal() == IDCANCEL)
return;
_TCHAR sFileName[255];
BeginWaitCursor();
UpdateData(true);
_tcscpy(sFileName, FileDialog.GetFileName());
sourceFile.open(sFileName,ios:ut);
if(!sourceFile.is_open())
AfxMessageBox("file for saving not opened");
else
for (POSITION Pos1 = pFrame->Batch_boardList.GetHeadPosition(); Pos1 != NULL
sourceFile <<pFrame->Batch_boardList.GetNext(Pos1)+'\n';
sourceFile.close();
-
November 9th, 2009, 02:27 PM
#3
Re: Problem on using VC++ 2008
I'd do some more changes:
Code:
CFileDialog FileDialog(FALSE, _T("txt"), _T("downloader"), OFN_CREATEPROMPT|OFN_HIDEREADONLY |
OFN_SHOWHELP|OFN_OVERWRITEPROMPT|OFN_LONGNAMES, _T("Save the file as (*.txt)|*.txt||)");
if (FileDialog.DoModal() == IDCANCEL)
return;
_TCHAR sFileName[MAX_PATH]; // 260, not 255
BeginWaitCursor();
UpdateData(true);
_tcscpy(sFileName, FileDialog.GetFileName());
sourceFile.open(sFileName, ios:ut);
if(!sourceFile.is_open())
AfxMessageBox( _T("file for saving not opened"));
else
for (POSITION Pos1 = pFrame->Batch_boardList.GetHeadPosition(); Pos1 != NULL
sourceFile << pFrame->Batch_boardList.GetNext(Pos1) + _T('\n');
sourceFile.close();
Victor Nijegorodov
-
November 10th, 2009, 10:26 AM
#4
Re: Problem on using VC++ 2008
Thank u victor & Hox...
I've cleared the problem.... n modified it like this...
#include<ifstream>;
using namespace std;
ifstream 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||"),NULL,0,TRUE);
if (FileDlg.DoModal() == IDCANCEL)
return;
_TCHAR sFileName[255];
BeginWaitCursor();
UpdateData(true);
_tcscpy(sFileName, FileDlg.GetFileName());
sourcefile.open(sFileName,ios:ut);
if(!sourcefile.is_open())
AfxMessageBox(_T("file for saving not opened"));
else
for (POSITION Pos1 = parList.GetHeadPosition(); Pos1 != NULL
sourcefile<< parList.GetNext(Pos1)+'\n';
sourcefile.close();
Now the file is created.... but when it is opening, the data in the listbox is not there... Some unknown Hexadecimal values are seeing there...
How to resolve it??
-
November 10th, 2009, 10:48 AM
#5
Re: Problem on using VC++ 2008
1) Does GetNext() return a CString ? Maybe the streams do not understand how
to output a CString and it is using the void* conversion (basically, printing
out the address of the object). Try casting to LPCTSTR
Code:
sourcefile<< (LPCTSTR)parList.GetNext(Pos1)<< '\n';
2) Depending an compiler options, you might need to change to
wifstream (also why istream types if outputing ?).
3) If GetNext() does return a CString, it would make more sense to use the
CStdioFile class which can directly read/write Cstring objects.
-
November 10th, 2009, 10:52 AM
#6
Re: Problem on using VC++ 2008
Originally Posted by arunkr6
... Now the file is created.... but when it is opening, the data in the listbox is not there... Some unknown Hexadecimal values are seeing there...
How to resolve it??
What listbox do you mean? I don't see any...
Victor Nijegorodov
-
November 11th, 2009, 08:27 AM
#7
Re: Problem on using VC++ 2008
Sorry Victor, for not providing sufficient data...
I've entered the datas of Listbox to a CStringList parList.
GetNext() returns CString itself... I've verified and it gives the exact data in particular CStringList. I hope the prblm is in the line 'sourcefile<<Parlist.Get....... Here the data is not loading to fstream sourcefile.
I've tried wifstream and ifstream.It gives an error as binary '<<' no operator found which takes a left hand operand of type std::wifstream.. So I've used fstream and it's working...
The problem still exists.....As the data written is something hexvalue(hope the address)....
-
November 11th, 2009, 08:54 AM
#8
Re: Problem on using VC++ 2008
Did you try the cast as I posted earlier ?
-
November 11th, 2009, 09:16 AM
#9
Re: Problem on using VC++ 2008
Is parList an CAtlList? How is it defined (what is the type parameter)?
-
November 11th, 2009, 12:41 PM
#10
Re: Problem on using VC++ 2008
Ya... I've casted it... Bt it doesn't resemble any change..same effect..
parList is assigned as CStringList only..
Can you plz give me a code to save and load the datas(user entering in fields and it combines to a ListBox) to a file....This is my requirement.. By using the above code I've done it in VC++ 6.0... Bt here it failed,,.!!
-
November 11th, 2009, 12:53 PM
#11
Re: Problem on using VC++ 2008
Originally Posted by arunkr6
Ya... I've casted it... Bt it doesn't resemble any change..same effect..
parList is assigned as CStringList only..
Can you plz give me a code to save and load the datas(user entering in fields and it combines to a ListBox) to a file....This is my requirement.. By using the above code I've done it in VC++ 6.0... Bt here it failed,,.!!
Why don't you just post your complete code and we'll suggest how to fix your code?
-
November 11th, 2009, 01:12 PM
#12
Re: Problem on using VC++ 2008
the exact code has pasted already..plz check above...
That's the code I've written for this function(Save to a file).
-
November 11th, 2009, 02:12 PM
#13
Re: Problem on using VC++ 2008
Originally Posted by arunkr6
the exact code has pasted already..plz check above...
That's the code I've written for this function(Save to a file).
Use code tags & more people will read it.
-
November 11th, 2009, 02:22 PM
#14
Re: Problem on using VC++ 2008
Originally Posted by arunkr6
the exact code has pasted already..plz check above...
The code has smiley faces and is unformatted. Why not fix it the formatting first by using code tags?
Regards,
Paul McKenzie
-
November 11th, 2009, 04:03 PM
#15
Re: Problem on using VC++ 2008
Originally Posted by arunkr6
the exact code has pasted already..plz check above...
That's the code I've written for this function(Save to a file).
You talk about the data not getting into a listbox, but there isn't any listbox code. How about posting the complete code?
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
|