Created
December 11, 2016 14:43
-
-
Save raaka1/8a0c6627f0db610ea9b4e68191781eef to your computer and use it in GitHub Desktop.
LEVELDB hello world
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cassert> | |
| #include <leveldb/db.h> | |
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| int main() { | |
| leveldb::DB* db; | |
| leveldb::Options options; | |
| options.create_if_missing = true; | |
| leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db); | |
| assert(status.ok()); | |
| string key = "foo"; | |
| string value = "bar"; | |
| cout << "write Key:" << key << " and value:" << value << endl; | |
| status = db->Put(leveldb::WriteOptions(), key, value); | |
| assert(status.ok()); | |
| string value_back; | |
| status = db->Get(leveldb::ReadOptions(), key, &value_back); | |
| cout << "Read back:" << value_back << endl; | |
| assert(status.ok()); | |
| assert(value == value_back); | |
| delete db; | |
| return 0; | |
| } | |
| //http://wiki.dreamrunner.org/public_html/C-C++/Library-Notes/LevelDB.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment