?
Solved

serialization ...

Posted on 1998-11-25
6
Medium Priority
?
208 Views
Last Modified: 2010-04-01
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 .
0
Comment
Question by:charul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 40 total points
ID: 1178645
I would go the simple way, with a CFile object.

Off the top of my head:

Writing:

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

for(int i=0;i<m_combo.GetCount();i++) {
 m_combo.GetLBText(i, szItem);
 file.WriteString(szItem);
 file.WriteString(_T("\n"));
}

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

m_combo.ResetContent();
while( file.ReadString(szItem) ) {
 m_combo.AddString(szItem);
}

Note: you should encapsultae this in try..catch for file exceptions and add some customization.
0
 

Author Comment

by:charul
ID: 1178646
I think WriteString is not a member of CFile class, in the above code that u have mentioned.
Please look into it.
0
 

Author Comment

by:charul
ID: 1178647
WriteString is a member function of CArchive class should i have an object of that and the use WriteString to write into the file
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:plaroche
ID: 1178648
Sorry, replace CFile by CStdioFile.
0
 

Author Comment

by:charul
ID: 1178649
why is _T used while creating the file. I am getting an exception when executing this code.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1178650
_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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question