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

serialization ...

Posted on 1998-11-25
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 .
Question by:charul
  • 3
  • 2

Accepted Solution

plaroche earned 20 total points
ID: 1178645
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.

Author Comment

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

Author Comment

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Expert Comment

ID: 1178648
Sorry, replace CFile by CStdioFile.

Author Comment

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

Expert Comment

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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 clear a vector as well as how to detect empty vectors in C++.

790 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