⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testmap.cxx

📁 完全免费的邮件发送程序。delphi 6.0
💻 CXX
字号:
//-< TESTMAP.CXX >---------------------------------------------------*--------*
// POST++                     Version 1.0        (c) 1998  GARRET    *     ?  *
// (Persistent Object Storage)                                       *   /\|  *
//                                                                   *  /  \  *
//                          Created:     31-May-99    K.A. Knizhnik  * / [] \ *
//                          Last update: 31-May-99    K.A. Knizhnik  * GARRET *
//-------------------------------------------------------------------*--------*
// Example of using STL map class with POST++
//-------------------------------------------------------------------*--------*

#include "post_stl.h"
#include <iostream>
#include <string>
#include <map>

#ifndef NO_NAMESPACES
using namespace std;
#endif

typedef map<string, string, less<string> > barmap;

int main()
{
    storage sto("bar.odb");
    if (sto.open(storage::fixed)) { 
        barmap* root  = (barmap*)sto.get_root_object();
	//
	// Microsoft implementation of STL map class uses _Tree template
	// which contains static _Nil component. This component is initialized 
	// by _Init() function when constructor of this class is called first 
	// time. To preserve the same address for this _Nil objects, 
	// programmer should create instances of all used map classes 
	// within begin_static_data, end_static_data section. In this case
	// post_alloc will return the same addresses for _Nil objects.
	//
	sto.begin_static_data();
	barmap* dummy = new (sto) barmap; 
	sto.end_static_data();
        if (root != NULL) { 
            for (barmap::iterator i = root->begin(); i != root->end(); i++) {
                cout << "Key=" << (*i).first 
		     << ", value=" << (*i).second << '\n';
            }
        } else { 
            root = new (sto) barmap;
            sto.set_root_object((object*)root);
	}
	cout << "Add some pairs. Type '.' to exit. Type '*' to clear the content.\n";
	while (true) { 
	    string key;
	    string value;
	    cout << "Key: ";
	    cin >> key;
	    if (key == ".") { 
		break;
	    }

	    //
	    //
	    //
	    if (key == "*") {

	      root->clear ();
	      continue;
	    }
	    //
	    //
	    //

	    cout << "Value: ";
	    cin >> value;
	    cout << "Key = " << key << ", Value = " << value << '\n';
#if 1
	    root->insert(barmap::value_type(key, value));
#else
	    root->insert(barmap::value_type(*new (sto) string(key), 
					    *new (sto) string(value)));
#endif
	}
	sto.flush();
	sto.close();
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -