#include <iostream>#include<string>#include<leveldb/db.h>#include<boost/lexical_cast.hpp>using namespacestd;intMainintargcChar*Const*argv) { Try{leveldb::D b*DB; Leveldb::options Options; Options.create_if_missing=true; Leveldb::status Status= Leveldb::D b::open (Options,"./db", &db); cout<< Status.ok () <<Endl; for(intI=0; i<99999; i++) { stringKey = boost::lexical_cast<string>(i); stringValue = boost::lexical_cast<string> (i*i); DB-Put (Leveldb::writeoptions (), key, value); } stringKey ="666"; stringvalue; DB->get (Leveldb::readoptions (), Key, &value); cout<< value <<Endl; cout<<666*666<<Endl; Delete db; } Catch(Exception &e) {cout<< e.what () <<Endl; } return 0;}
Code is not special, because QT creator in the compile time will be added -mmacosx-version-min=10.6 such parameters, so we compile LIBLEVELDB.A time also need to add this parameter, otherwise under QT will error.
The. Pro file needs to add these two lines:
LIBS + =-l/opt/local/lib/-lleveldb
Includepath + =/opt/local/include
Simple reading and writing of LEVELDB with Qt Creator