Simple reading and writing of LEVELDB with Qt Creator

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.