64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
//#include <windows.h>
typedef string CRect;
typedef string CSize;
typedef string COLORREF;
typedef bool BOOL;
typedef unsigned int UINT;
class CMyTracker
{
public:
UINT m_nStyle; // current state
CRect m_rect; // current position (always in pixels)
CSize m_sizeMin; // minimum X and Y size during track operation
int m_nHandleSize; // size of resize handles (default from WIN.INI)
//当前矩形边框颜色
COLORREF m_rectColor;
//当前矩形填充颜色
COLORREF m_bkColor;
BOOL m_bAllowInvert; // flag passed to Track or TrackRubberBand
CRect m_rectLast;
CSize m_sizeLast;
BOOL m_bErase; // TRUE if DrawTrackerRect is called for erasing
BOOL m_bFinalErase; // TRUE if DragTrackerRect called for final erase
CRect m_LimitRect; //限定tracker的活动区域
friend ofstream& operator<<(ofstream& ofs, const CMyTracker& tracker);
friend ifstream& operator>>(ifstream& ifs, CMyTracker& tracker);
};
typedef vector<CMyTracker> Containter;
/*
template<typename T>
ofstream& operator<<(ofstream& ofs, const vector<T>& vec)
{
ofs << vec.size() << endl;
for(vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
ofs << *it;
}
return ofs;
}
*/
ofstream& operator<<(ofstream& ofs, const CMyTracker& tracker)
{
//todo
ofs << tracker.m_nStyle << " , ";
ofs << tracker.m_rect << " , ";
// ...
ofs << tracker.m_LimitRect << endl;
return ofs;
}
ifstream& operator>>(ifstream& ifs, CMyTracker& tracker)
{
//todo
string s;
ifs >> tracker.m_nStyle >> s;
ifs >> tracker.m_rect >> s;
ifs >> tracker.m_LimitRect;
return ifs;
}
ofstream& operator<<(ofstream& ofs, const Containter& vec)
{
ofs << vec.size() << endl;
for(Containter::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
ofs << *it;
}
return ofs;
}
ifstream& operator>>(ifstream& ifs, Containter& vec)
{
string s;
Containter::size_type size = 0;
ifs >> size;
if(!vec.empty())
{
vec.clear();
}
while(size--)
{
CMyTracker tracker;
ifs >> tracker;
vec.push_back(tracker);
}
return ifs;
}
int
main(int argc, char *argv[])
{
Containter vec, vec2;
CMyTracker trk;
trk.m_nStyle = 1;
trk.m_rect = "m_rect1";
trk.m_LimitRect = "m_LimitRect1";
vec.push_back(trk);
trk.m_nStyle = 2;
trk.m_rect = "m_rect2";
trk.m_LimitRect = "m_LimitRect2";
vec.push_back(trk);
ofstream ofs("demo017.txt");
ofs << vec;
ofs.close();
ifstream ifs("demo017.txt");
ifs >> vec2;
cout << "=============" << endl;
cout << vec2.size() << endl;
for (Containter::const_iterator it = vec2.begin(); it != vec2.end(); ++it) {
cout << (*it).m_nStyle << endl;
cout << (*it).m_rect << endl;
cout << (*it).m_LimitRect << endl;
}
return 0;
}
#include <fstream>
#include <vector>
#include <windows.h>
using namespace std;
class CMyTracker
{
UINT m_nStyle; // current state
CRect m_rect; // current position (always in pixels)
CSize m_sizeMin; // minimum X and Y size during track operation
int m_nHandleSize; // size of resize handles (default from WIN.INI)
//当前矩形边框颜色
COLORREF m_rectColor;
//当前矩形填充颜色
COLORREF m_bkColor;
BOOL m_bAllowInvert; // flag passed to Track or TrackRubberBand
CRect m_rectLast;
CSize m_sizeLast;
BOOL m_bErase; // TRUE if DrawTrackerRect is called for erasing
BOOL m_bFinalErase; // TRUE if DragTrackerRect called for final erase
CRect m_LimitRect; //限定tracker的活动区域
friend ofstream& operator<<(ofstream& ofs, const CMyTracker& tracker);
friend ifstream& operator>>(ifstream& ifs, CMyTracker& tracker);
};
typedef vector<CMyTracker> Containter;
ofstream& operator<<(ofstream& ofs, const CMyTracker& tracker)
{
//todo
return ofs;
}
ifstream& operator>>(ifstream& ifs, CMyTracker& tracker)
{
//todo
return ifs;
}
ofstream& operator<<(ofstream& ofs, const Containter& vec)
{
ofs << vec.size();
for(Containter::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
ofs << *it;
}
return ofs;
}
ifstream& operator>>(ifstream& ifs, Containter& vec)
{
Containter::size_type size = 0;
ifs >> size;
if(!vec.empty())
{
vec.clear();
}
while(size--)
{
CMyTracker tracker;
ifs >> tracker;
vec.push_back(tracker);
}
return ifs;
}
剩下的自己去写吧