Thread: Apending to a .dat File using ofstream

  1. #1
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    234

    Apending to a .dat File using ofstream

    Hey evrbdy, Iam.TheJinx(who *cares);

    Alas, another problem has arisen in my desparate attemp at VC. I am tryig to use the ofstream method of appending to a file. What is wrong with this source:
    (Already declared the CStrings m_str's below, IDC_NAME is an Edit Box, and make sure to #include fstream.h)


    void::OnSave()
    {
    char m_strName[100];
    CDataDlg::GetWindowText(IDC_NAME, <--need help here-->);

    <--Something to put the IDC_NAME string to strName[100];-->

    ofstream dFile;
    dFile.Open("data.dat");
    dFile<<"Name: "<<m_strName<<"\n";
    dFile<<"-------------------------------\n\n\n";
    //etc. of dFile<<".." below
    dFile.close();
    }
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    try:

    Open("filename.dat", ios::out | ios::app);

    to open a ofstream in append mode

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Code:
    void::OnSave() 
    {
         //Get the text
         CString Var1 = m_strName.GetWindowText();//Easy way to do it
    
         //Output to file
         ofstream dFile; 
         dFile.Open("data.dat", ios::out | ios::app); Added from The V
         dFile<<"Name: "<<Var1<<"\n"; //Made change here
         dFile<<"-------------------------------\n\n\n"; 
         //etc. of dFile<<".." below 
         dFile.close(); 
    }
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  4. #4
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    234

    Alrighty then...

    .. I am at our oublic library and wanted to check for some replies. Thanks for your help guys, i try to get my code in tonight, if it doesn't work (I'm sure it will) then I'll post another reply
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  5. #5
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    234

    Angry Uh-oh!!!

    None of the above worked for me. I tried every way could to get these to work, but couldn't, any way I tried, whats up?
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM