作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
570 B

  1. #include "leveldb/db.h"
  2. #include <iostream>
  3. using namespace std;
  4. using namespace leveldb;
  5. int main() {
  6. DB* db = nullptr;
  7. Options op;
  8. op.create_if_missing = true;
  9. Status status = DB::Open(op, "testdb", &db);
  10. assert(status.ok());
  11. db->Put(WriteOptions(), "001", "leveldb", 20);
  12. string s;
  13. auto stat = db->Get(ReadOptions(), "001", &s);
  14. cout<<s<<endl;
  15. cout<<stat.ok()<<endl;
  16. db->Put(WriteOptions(), "002", "world");
  17. string s1;
  18. db->Delete(WriteOptions(), "002");
  19. db->Get(ReadOptions(), "002", &s1);
  20. cout<<s1<<endl;
  21. delete db;
  22. return 0;
  23. }