CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
  1. #16
    Join Date
    Oct 2008
    Posts
    59

    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???

  2. #17
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    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');

  3. #18
    Join Date
    Oct 2008
    Posts
    59

    Unhappy Re: Problem on using VC++ 2008

    Ya.. I've compiled it.....

    This only returns the file with some unknown data..

  4. #19
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  5. #20
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    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.

  6. #21
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Problem on using VC++ 2008

    Quote Originally Posted by Philip Nicoletti View Post
    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.

  7. #22
    Join Date
    Oct 2008
    Posts
    59

    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??

  8. #23
    Join Date
    Feb 2005
    Posts
    2,160

    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 *).

  9. #24
    Join Date
    Oct 2008
    Posts
    59

    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..

    ??

  10. #25
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  11. #26
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Problem on using VC++ 2008

    Quote Originally Posted by arunkr6 View Post
    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

  12. #27
    Join Date
    Oct 2008
    Posts
    59

    Re: Problem on using VC++ 2008

    I havn't defined it as UNICODE.

  13. #28
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Problem on using VC++ 2008

    Apps built by the AppWizard should default to UNICODE in VS2005 and later.

  14. #29
    Join Date
    Oct 2008
    Posts
    59

    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.

  15. #30
    Join Date
    Oct 2008
    Posts
    59

    Re: Problem on using VC++ 2008

    thank u..

    it got worked.. i jus changed 2 wfstream.... got the problems,,

    thank u..all

Page 2 of 2 FirstFirst 12

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
  •  





Click Here to Expand Forum to Full Width

Featured