Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:30:37+00:00 2026-05-25T15:30:37+00:00

I have to map containers: map<string, char *> mOServs; map<LPWCH, int> mymap; I do

  • 0

I have to map containers:

map<string, char *> mOServs;

map<LPWCH, int> mymap;

I do a sqlite3 query and try to update these two maps with the results:

sprintf_s(query,1024,"SELECT oservname FROM OServs;");
rc = sqlite3_get_table(db, query, &results, &nrow, &ncol, &zErrMsg);
    cout << "query: " << query << endl;
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Error Selecting oserv name: %s\n", zErrMsg);
        sqlite3_free_table(results);
        sqlite3_close(db);
        return -1;
    }

int X = 0;
WCHAR somevar[1024];

while(X < nrow)
{
    mbstowcs(somevar, results[X+1], 1024 );
    wcstombs(output, somevar, 1024);
    mOServs[output] = "offline";
    mymap[somevar] = X;
    X++;

}

Somehow mOServs seems to populate properly, but with mymap, it only contains the last record of the query at the end of the loop. Am I doing something wrong?

I am trying to store all the query results in a map, and so that, I can do a mymap.find(LPWCH), to find if a record is in the table or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:30:37+00:00Added an answer on May 25, 2026 at 3:30 pm

    Perhaps you meant to do something more like this:

    map<int, std::wstring> mymap;
    for(int i(0); i < nrow; ++i)
    {
    // ...
        mymap[i] = somevar;
    }
    

    Edit: Actually why do you need a map here at all? std::vector would probably suffice it doesn’t make much sense to have either the key or the value of the map be set to a temporary loop count value.

    Edit#2: Actually I just realized something else crazy is happening. First you convert from char* to wchar_t* then on the very next line you convert it right back from wchar_t* to char*.

    mbstowcs(somevar, results[X+1], 1024 );
    wcstombs(output, somevar, 1024);
    

    This is unnecessary. Decide if you want to use std::string or std::wstring and prefer these objects. Mixing and matching character arrays, with pointers to arrays, with typedefs of pointers to array, with string objects, and also mixing wide character and multibyte characters is just asking for trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some thing like this code: map<int, string> m; m[1] = a; m[2]
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have a map declared as follows: map < string , list < string
I have the following class: #include <string> #include <stack> #include <queue> #include map.h using
Suppose I have a struct containing a std::string, like this: struct userdata{ int uid;
I have this map which compiles fine in MSVC10 : std::map<std::string, std::ofstream> m_logFiles; But
I have code like this: class MapIndex { private: typedef std::map<std::string, MapIndex*> Container; Container
So I have a container(any kind, probably std::map or std::vector) which contains objects of
I have a service that contains a map: static Map cargosMap = ['1':'item1','2':'item 2','3':'item
I have map.resources :posts and I want to be able to serve post bodies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.