serialization ...

My application is dialog based,
i would like to know how could i write data into a file , that which i read from the combo box and when i start my application, read from the file and initliaze the combo bo with the file content .
Who is Participating?

Improve company productivity with a Business Account.Sign Up

plarocheConnect With a Mentor Commented:
I would go the simple way, with a CFile object.

Off the top of my head:


CFile    file(_T("mycombo.cnt"), CFile::modeCreate);
CString  szItem;

for(int i=0;i<m_combo.GetCount();i++) {
 m_combo.GetLBText(i, szItem);

CFile    file(_T("mycombo.cnt"), CFile::modeRead);
CString  szItem;

while( file.ReadString(szItem) ) {

Note: you should encapsultae this in try..catch for file exceptions and add some customization.
charulAuthor Commented:
I think WriteString is not a member of CFile class, in the above code that u have mentioned.
Please look into it.
charulAuthor Commented:
WriteString is a member function of CArchive class should i have an object of that and the use WriteString to write into the file
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Sorry, replace CFile by CStdioFile.
charulAuthor Commented:
why is _T used while creating the file. I am getting an exception when executing this code.
_T is the macro to handle Unicode or ANSI text literals.

If you program is always going to be compiled as ANSI (8 bits per character), just leave it out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.