Thread: saving a CString to binary file with trailing spaces

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And definitely not on binary writes. Besides, I was asking the OP, not you. It might be that his code has a bug. Actually I'm convinced his code has a bug.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by CornedBee
    Besides, I was asking the OP, not you. It might be that his code has a bug. .
    Myapologies for misunderstanding you.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    8
    Code:
    class RecAdj 
    {
    public:
    	RecAdj();
    
    	char m_invoice_c11[11];
    
    	void ReadRec(int number, CListBox* pListBox);
    	void SaveRecItem(CString filename);
    
    };
    
    
    void CRegisterDoc::OnReceive() 
    {
    	// TODO: Add your command handler code here
    	VendorDlg adlg;
    	if(adlg.DoModal() == IDOK)
    	{
    		RecItemdlg recdlg;
    		do
    		{
    			//adlg.m_invoicenumber is a CString its value here would ex. "Bob" with no spaces.
    			strcpy(recdlg.recitem.m_invoice_c11 , adlg.m_invoicenumber);
    		}while(recdlg.DoModal()==IDOK);
    	}//endif
    }
    
    
    
    void RecAdj::SaveRecItem(CString filename)
     {
     	std::ofstream fout(filename, std::ios::binary | std::ios::app);
     	if(fout.fail())
     		AfxMessageBox("Temp rec file failed to open", MB_OK);
    	else
    	{
     
      		fout.write(m_invoice_c11, sizeof(m_invoice_c11)); //as is "Bob........" is the output
    	}
    	fout.close();
     }
    the above is the acutall code minus the call funtion to SaveRecItem. Its called from another function but doesn't change or affect the data in anyway. I have stripped this down to be only one variable, in the actual code there are lots more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM