0

How can i use dbstl::db_map<string, list< string>>? I use Berkeley DB STL in C++ and Visual Studio 2015

I want to use list< string> as value of db_map, but i get an error. I understand that no one does this, but i need to do this on assignment. How can i fix this error? Perhaps there is some alternative solution?

My code:

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "libdb181.lib")
#pragma comment(lib, "libdb_stl181.lib")

#include "stdafx.h"
#include <iostream>
#include <dbstl_map.h>
#include <list>
using namespace std;

int main(){
    const char* db_name = "db";
    const char* db_home_dir = "dbdir";

    DbEnv env(DB_CXX_NO_EXCEPTIONS);
    Db* pdb;

    try {
        dbstl::dbstl_startup();

        env.set_error_stream(&cerr);
        env.open(db_home_dir, DB_CREATE | DB_INIT_MPOOL, 0);

        pdb = new Db(&env, DB_CXX_NO_EXCEPTIONS);
        pdb->open(NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0);

        typedef dbstl::db_map<string, list<string>> dbmap_list;
        dbmap_list map_list(pdb, &env);

        string key_list = "list";
        list<string> value_list;
        value_list.push_back("first"); value_list.push_back("second");
        map_list.insert({ key_list, value_list });
        
        list<string> outvalue_list = map_list[key_list];
        list<string>::iterator it = outvalue_list.begin();
        cout << *it;

        dbstl::dbstl_exit();

        if (pdb != NULL) {
            pdb->close(0);
            delete pdb;
        }
        env.close(0);

    

    }
    catch (DbException& e) {
        cerr << "DbException: " << e.what() << endl;
        _sleep(5000);
        return -1;
    }
    catch (std::exception& e) {
        cerr << e.what() << endl;
        _sleep(5000);
        return -1;
    }

    cout << "hello";
    _sleep(5000);
    return 0;
}

My error:

Program: C:\Windows\SYSTEM32\MSVCP140D.dll File: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\list Line: 211

Expression: list iterator not dereferencable

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application) ConsoleApplication8.exe has triggered a breakpoint.

Debug Assertion Failed!

Program: ..._V36\p1\ConsoleApplication8\x64\Debug\ConsoleApplication8.exe File: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\list Line: 212

Expression: "Standard C++ Libraries Out of Range" && 0

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application) 'ConsoleApplication8.exe' (Win32): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. 'ConsoleApplication8.exe' (Win32): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. 'ConsoleApplication8.exe' (Win32): Unloaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll' 'ConsoleApplication8.exe' (CLR v4.0.30319: ConsoleApplication8.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Unhandled exception at 0x00007FFB60CF10CB (ucrtbased.dll) in ConsoleApplication8.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.

3
  • do you have to use std::list ? Often it can be replaced by std::vector, maybe this already helps. We already know that dbstl_map is a little weird ;) Commented Jan 12, 2023 at 21:52
  • @463035818_is_not_a_number i also tried vector<string>, but it causes similar errors. Perhaps such a solution is unacceptable, but what alternative solutions can there be so that i can save a list of strings? Commented Jan 12, 2023 at 22:01
  • I'm thinking of serializing the list and using it as a string, but maybe there is some other solution Commented Jan 12, 2023 at 22:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.