943,668 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1401
  • C RSS
Nov 18th, 2005
0

Saving to a file

Expand Post »
What is the best way to save to a file using a MFC Dialog based program? I need it to output mutipule data type (CString, int) to a file. I also need it to read the data from the file to update the controls (i.e. an options dialog). I've tried using ifstream, and ostream, but to no avail. I can output the int fine, but the CString is another story. If the CString is a control ( or was a control) then the output looks weird (I get 7 numbers followed by one letter, I think it's OCT?). And I can't get it to read properly from the file. How do I do this? Should I be using something else to save?

Thanx,
Atrus
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Nov 18th, 2005
0

Re: Saving to a file

You can check out CFile, if you want to stick with the MFC stuff and not mess with STL or the C file input/output functions. For CFile:

http://msdn.microsoft.com/library/de..._MFC_CFile.asp

As for how to write a string to a file using STL, you should be using the GetBuffer() and GetLength() methods of CString and then writing to the file as a character array, you shouldn't be using the << and >> operators, those do something slightly different for CString objects than they do for regular stl string objects.

-Fredric
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Permutation of any word short and fast without pointers
Next Thread in C Forum Timeline: How to perform pow(x,y) where x and y are floats??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC