Boost::program_options

This is a discussion on Boost::program_options within the C++ Programming forums, part of the General Programming Boards category; I have a problem when I try to convert value which I get from config file - i believe it ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115

    Boost::program_options

    I have a problem when I try to convert value which I get from config file - i believe it is vector, although I don't know anything about vectors...

    I get an exception error:
    boost::bad_any_cast: failed conversion using boost::any_cast
    And here's the code (converting):

    Code:
    config::variables_map vm; 
    // ...
    const char *data_db = vm["data_db"].as<char*>();
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    905
    Gotta know what class it is.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    config is a namespace - equal to boost :: program_options...
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Use std::string instead. I don't know if program options works with char*.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    I solved it out myself (using std::string). Thanks anyway!!
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21