Solved

serialization ...

Posted on 1998-11-25
6
200 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
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 20 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now