[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

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 .
0
charul
Asked:
charul
  • 3
  • 2
1 Solution
 
plarocheCommented:
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
 
charulAuthor Commented:
I think WriteString is not a member of CFile class, in the above code that u have mentioned.
Please look into it.
0
 
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
plarocheCommented:
Sorry, replace CFile by CStdioFile.
0
 
charulAuthor Commented:
why is _T used while creating the file. I am getting an exception when executing this code.
0
 
Answers2000Commented:
_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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now