Does anyone have an easy way to load and save a wxArrayString from and to a file ?
Thanks
loading and saving wxArrayString
-
- Earned a small fee
- Posts: 11
- Joined: Fri Jan 07, 2005 4:57 pm
- Location: NM USA
-
- wxWorld Domination!
- Posts: 1387
- Joined: Thu Aug 18, 2005 7:49 pm
- Location: Germany
write all entries to file.
Before store how much items are there.
Then, when loading, read first the number of items,
then read the items and append to your array.
I have written a helperfunction a few month ago, to save STL like containers:
its basicly the same with wxStringArray, just a different interface.
Before store how much items are there.
Then, when loading, read first the number of items,
then read the items and append to your array.
I have written a helperfunction a few month ago, to save STL like containers:
Code: Select all
template<class cont> void contwriter(std::ostream& out,const cont& container)
{
out << container.size() <<' ';
typename cont::iterator begin=container.begin();
typename cont::iterator end = container.end();
// if(begin == end) return;
for(;begin != end; ++begin)
out << *begin << ' ';
}
template<class cont, class T> void contreader(std::istream& in, cont& container)
{
std::size_t n;
in >> n;
if(n > 0)
{
T t;
for(std::size_t i =0; i < n; ++i)
{
in >> t;
container.push_back(t);
}
}
}
-
- Earned a small fee
- Posts: 11
- Joined: Fri Jan 07, 2005 4:57 pm
- Location: NM USA
-
- Filthy Rich wx Solver
- Posts: 210
- Joined: Sat May 07, 2005 8:24 pm
- Location: Eskisehir, TURKEY
Code: Select all
bool SaveArrayStringToFile(wxString strFileName,const wxArrayString &aryStr)
{
wxTextFile txtFile(strFileName);
txtFile.Create();
for(int i=0;i<aryStr.GetCount();i++)
{
txtFile.AddLine(aryStr.Item(i));
}
txtFile.Close();
return true;
}
bool LoadArrayStringFromFile(wxString strFileName,wxArrayString &aryStr)
{
aryStr.Clear();
wxTextFile txtFile(strFileName);
txtFile.Open();
if (txtFile.IsOpened() == FALSE)
{
return false;
}
int TotalLines = txtFile.GetLineCount();
for(int i=0;i<txtFile.GetLineCount();i++)
{
aryStr.Add(txtFile.GetLine(i));
}
return true;
}
- T U R K E Y ?
- I love this country!
WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/
- I love this country!
WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/
-
- Earned a small fee
- Posts: 11
- Joined: Fri Jan 07, 2005 4:57 pm
- Location: NM USA
-
- Moderator
- Posts: 3971
- Joined: Fri Aug 27, 2004 9:38 pm
- Location: Delft, Netherlands
Try wxArchive, it allows you to serialize wxArrayStrings to any wxOutputStream.
http://wastebucket.solidsteel.nl/cms/mo ... k=WiwiHome
- Jorgen
http://wastebucket.solidsteel.nl/cms/mo ... k=WiwiHome
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb