How can I put a stl::vector string into the DB and then get it out?

Hello,
As the title, here's a test case with problems,but anyway you can still run it. ( VC6/XP-32/BDB 4.7 )
I know this may be wrong,and I'd like to know how can I do this.
Can someone help me please? I would appreciate it very much.
************ Copy,Compile and Run ***************
#include <iostream>
#include <vector>
#include "db_cxx.h"
int main()
     std::string dbName("database.db");
     u_int32_t db_flags=DB_CREATE;
     Db* db=NULL;
     // Prepare key(int)/data(vector<string>) pair.
     int int_key=2;
     std::vector<std::string> rec_data;
     rec_data.push_back("apple");
     rec_data.push_back("Bob");
     rec_data.push_back("Me");
     // Prepare Dbt for receiving.
     std::vector<std::string> rec_readData;
     Dbt readData;
     readData.set_data(&rec_readData);
     readData.set_ulen(sizeof(rec_readData));
     readData.set_flags(DB_DBT_USERMEM);
     try
          // Open database.
          db = new Db(NULL,0);
          db->open(NULL,dbName.c_str(),NULL,DB_BTREE,db_flags,0);
          // Put
          int ret;
          if(ret=db->put(NULL,new Dbt(&int_key,sizeof(int_key)),new Dbt(&rec_data,sizeof(rec_data)),DB_NOOVERWRITE)==0)
               std::cout<<"put successful!"<<std::endl;
          else { db->err(ret,"Db->put"); }
          // Get
          if(ret=db->get(NULL,new Dbt(&int_key,sizeof(int_key)),&readData,0)==0)
               std::cout<<"get successful!"<<std::endl;
          else { db->err(ret,"Db->get"); }
     catch(DbException &e)
          std::cerr<<"Error: ";
          std::cerr<<e.what()<<std::endl;
     // Close the database
     try
          if(db!=NULL)
               db->close(0);
     catch(DbException &e)
          std::cerr<<"Error closing database: ";
          std::cerr<<e.what()<<std::endl;
     // Display the results.
     // Index out of bounds. <-----
     std::cout << rec_readData[0].c_str();
     std::cout << rec_readData[1].c_str();
     std::cout << rec_readData[2].c_str();
     system("pause");
     // Press any key to go wrong. :(
     return 0;
Regards,
legendsino

You need to convert the std::vector<std::string> into a sequence of bytes. For example, if all strings are shorter than 256 characters, you could create a fresh output string, iterator through the vector, and for each element, append the string length to the output string, followed by the string contents.
Note that ordering in the database will be different from lexicographic order, and you have to keep that in mind when performing range queries.

Similar Messages

  • Firefox crashes for unknown reason lately, so I removed it and reinstalled it. How can I put my Favorites (bookmarks) back into the newly installed FireFox???

    Firefox crashes a few times when I was on Facebook and with email, also watching dramas online. Most of the time due to Adobe Flash and I did submit crash report. Later it crashes for unknown reason while I have email and Facebook on different tabs -- when I was on the tab of email, it looks system hang and not responding. This happened to my laptop that uses Windows Vista as I noticed. I don't remember it ever happens to my desktop that uses Windows XP.
    It's pretty annoying of such known crash, but before removing Firefox, I did try to update all add-ons or plugins and it looks like doesn't work out. After updating for couple times and it still crashed like that, I removed Firefox and reinstall it.
    '''Now I want to know how to put the shortcuts from my Favorite folder into the newly installed FireFox's bookmarks.''' I didn't backup the bookmarks by using Firefox. I even went to Firefox help for instructions, but it only mentions how to merge/input the bookmarks from other browsers. Please note the version I've removed and inrestalled is the same -- 3.6.13.

    It is possible that there is a problem with the files sessionstore.js and sessionstore.bak in the Firefox Profile Folder.
    Delete the sessionstore.js file and possible sessionstore-##.js files with a number and sessionstore.bak in the Firefox Profile Folder.
    *Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    Deleting sessionstore.js will cause App Tabs and Tab Groups and open and closed (undo) tabs to get lost, so you will have to create them again (make a note or bookmark them).
    *http://kb.mozillazine.org/Multiple_profile_files_created
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Open Containing Folder

  • I've got my email folders showing but how can i put back my email messages into the folders from time machine

    my mac has been restored & i can see my email folders but how do i put back the saved emails from my time macine i can locate n see them but cant restore them

    Csound1 wrote:
    Into one of the domain accounts, or a specific mailbox in a domain account, that's your choice but:
    Remember that you are moving mail over the internet, and you are uploading (slower). If the quantities are large you must use caution.
    1. Copy, don't move, in the event of a failure the original will still exist, delete it later.
    2. Limit copies to <500 emails
    3. Single copy operations are more reliable than multiple.
    Take your time.
    Thanks, but impractical. Many of the folders have more than 500 emails. Total is about 2 GB (which I have free on iCloud btw)
    I tried creating a folder "Archive" in my iCloud, then tried dragging one iMac folder into the new "iCloud > Archive" folder on my iMac. I got the error message:
         Some items could not be created:
         The IMAP command “CREATE” failed with server error: Invalid mailbox name.

  • Can content be loaded from one PC into the iCloud and then accessed on another (new) PC?

    Can content that's loaded into the iCloud on one PC be accessed from the iCloud on another (new) PC?

    I think you have a few of options…
    Sign up for iTunes Match
    https://www.apple.com/itunes/itunes-match/
    That will allow you to use iCloud to 'match' then download all the songs that are in your library, it will try to replace songs that are available in the iTunes store, or it will copy the files into your iCloud account. This may take a while depending on your internet connection speed. Also see the limitations (like the 25,000 song limit).
    Copy the songs over to the new machine
    If you create a playlist in iTunes with all the relevant songs you should be able to drag them into a folder on another disk. This can be an USB drive or it could be the other computer (if you can setup how to share the disk & mount it on your old PC).
    You can then drag the folder of files into the iTunes Library on the other machine. That will copy all the files, however it will not create the playlists or the restore the play count's etc. It's safest to quit iTunes, open the "Automatically add to iTunes folder" in the media library and drop your files into that folder, then iTunes should import them all for you.
    iTunes 9: Understanding the "Automatically Add to iTunes" folder.
    Move everything to the new PC
    The final option would be to move all of the iTunes files & the library files to the new PC.
    iTunes: How to move your music to a new computer (see the 'external drive' section)
    This may not be an option if you have important media in both libraries because it replaces the entire iTunes library.
    Also don't forget to deauthorise the old PC if you don't want to use it with iTunes anymore, it's also on that last page I linked.

  • I have a projector connected to a directtv box that is connected to an older Bose system in my media room. How can i hook up my apple tv to my projector and still get sound out of the bose system without running another sound cable to the bose system?

    The audio cable currently is connected to the directtv box. If i hook my apple tv to the projector that means i would have to run a sound cable across my media room. is there any other way?

    External speakers need to be connected via optical unless they work with airplay.

  • How can i put view All in bottom of the grid view?

    Hi All,
    I have created a sharepoint document library and uploaded documents to that library.
    After that i have bind that documents to gridview, now i want put view All in the bottom of the documents.
    View All---> if i click this, it will navigate to that sharepoint library.
    How can i put view All in bottom of the grid view.

    Hi Anil,
    You can add a button or hyperlink and initialize the redirect url with default view url of list as "oList.DefaultView.Url".
    Best Regards,
    Brij K
    Best Regards,
    Brij K
    http://bloggerbrij.blogspot.co.uk/

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • I am trying to print a PDF file to a legal size paper and I would like for it to fill up the page. How do I do this? I went into the settings and changed it from letter to legal, but it's still printing out the same size. Can someone help me, please?

    I am trying to print a PDF file to a legal size paper and I would like for it to fill up the page. How do I do this? I went into the settings and changed it from letter to legal, but it's still printing out the same size. Can someone help me, please?

    Are you trying to Print to PDF or are you trying to Print a PDF file to a physical printer?

  • How can I view my full billing history for the app and music stores without iTunes installed?

    I just received an email receipt from Paypal showing a $12.99 purchase from iTunes. I almost NEVER purchase anything over around five dollars in the app or music store. Since PayPal does not show what this purchase was for, I have not received the receipt from Apple yet, and I cannot find anyway to look up online what this purchase was for....I need help to find out ASAP what this purchase was. If my account has been compromised or if I have been incorrectly charged for something, I would like to get the issue handled immediately. I do not want to install iTunes on my PC (nor should I have to for Pete's sake), but I cannot see anything recent at all in my app or music history on my iPad (not that I would ever purchase anything for $12.99 anyway...I just don't). Thanks in advance for any tips!

    How can I view my full billing history for the app and music stores without iTunes installed?
    No.
    If my account has been compromised
    If you even think this may have happened, immediately change your password.
    See this -> Apple ID: Changing your password

  • I have bought an iMAC second hand but when updates to purchased (not by me) Apps I cannot download the updates as it is asking for the original owners password. How can I amend this or could I delete the Apps and download new ones in place under my email

    I have bought an iMAC second hand but when updates to purchased (not by me) Apps I cannot download the updates as it is asking for the original owners password. How can I amend this or could I delete the Apps and download new ones in place under my email

    If the machine was upgraded to Lion 10.7.x by the original owner then you bought an illegal license of Lion and also of any other applications that the seller  said came pre-installed, this assumes the seller did not include original install media. In that case you need to contact the seller for the original install DVDs that came with the machine re-install up to Snow Leopard 10.6.8 and then purchase Mountain Lion ($20) and the applications you want or need. If the seller cannot come up with the original install discs then you can buy them from a nominal cost from AppleCare..

  • How can I view just music - not videos - in the libary and playlists?

    I've noticed that when creating smart playlists and viewing the libarary I cannot filter out videos... is there a way to do this without having to just uncheck the videos and pretend they aren't there or is this something that apple didn't think of?
    I want to create smart playlists to listen to in my car and want to back up my library on dvd-roms, that is where this becomes a problem. If anyone knows how to change the settings so that videos don't show up in certain playlists or on the libarary I would appreciate it a lot.

    How can I view my full billing history for the app and music stores without iTunes installed?
    No.
    If my account has been compromised
    If you even think this may have happened, immediately change your password.
    See this -> Apple ID: Changing your password

  • How can I remove a person's face from a photo and then replace the spot with a person's face from another photo?

    How can I remove a person's face from a photo and then replace the spot with a person's face from another photo?

    In Editor, go to the expert tab.
    Open picture B, the one you wish to select the "replacement" face from to add to another picture.
    Use one of the selection tools, e.g. selection brush, lasso tool, to select the face. You will see an outline ("marching ants") once the selection is complete
    Go to Edit menu>copy to copy the selection to the clipboard
    Open picture A, then go to Edit>paste
    Use the move tool to position the face from picture B to cover the face on A
    In the layers palette you should see picture A as the background layer, and face B on a separate layer

  • How can I find my playlists in this new interface?  And then, how can I transfer newly purchased songs to a playlist?

    how can I find my playlists in this new interface?  And then, how can I transfer newly purchased songs to a playlist?

    iCloud does not store messages for you to see/access at icloud.com.  It does back up messages so you can restore your iPhone if it ever needs to be reset to factory default.  A backup is an image of all your data on the iPhone, and if you delete some messages, then they won't be part of any further backups.
    If two people use the same iCloud account, then their devices are kept in sync, just like a single user's multiple devices are kept in sync.  It's usually a good idea to have separate accounts for two people, since it's rarely the case that they want each phone to be an exact replica of the other.
    Your iphone syncs contacts, events, camera roll, and many other things without the use of a computer.
    Read about icloud here...   http://www.apple.com/icloud/

  • Have an ipod and then got the wife an iphone4. all passwords are screwed up. she can not access playstore cuz she doesn't have password. i can not get find any help on how to get or update a password for the ipod. and then get her a separate password for

    have an ipod and then got the wife an iphone4. all passwords are screwed up. she can not access playstore cuz she doesn't have password. i can not get find any help on how to get or update a password for the ipod. and then get her a separate password for her iphone. we need to save her photos, music, etc to ? icloud and the phone stuff to verizon cloud? so when she gets her new Iphone6 she can have all her "stuff" back on the new phone. hope this makes sense. please offer suggestions here or at [email protected] thanks for your help!

    Oh no! I'm sorry to see there's a lot of confusion here and data shared, x-rayDon. We can definitely work to fix. This happens when two devices share the same Apple ID, so she will need to reset hers. She can do so by assessing this link Apple - My Apple ID. You will need to decide who will keep the account if want separate Apple IDs since purchases cannot be shared unless you do Family Sharing.
    RobinD_VZW
    Follow us on twitter @VZWSupport

  • How can I import Photoshop-Shortcuts from CC into the CC 2014 update?

    How can I import Photoshop-Shortcuts from CC into the CC 2014 update? Migration and Sync didn't help. What am I doing wrong? The .kys is also in the same folder as in the previous version of PS CC.
    Kindly
    Nico

    If you had Illustrator you could take advantage of smart objects.
    Has been awhile since I worked in Corel (so do not remeber if Corel had clipboard settings whcih need adjusuting), but do remember copying a path, getting that into Phothshop as shape layer for part of the artowrk in a trade show poster.

Maybe you are looking for