Mapping Managed C++ hashtable into native C++ map

  • Thread starter Stan Maydan. from NY
  • Start date
S

Stan Maydan. from NY

Hello,

I am having difficulty mapping Managed C++ hashtable into native C++
map (string to double). Somehow the double value is not mapped properly
(istead of value of 75 something like 10**(-308) is mapped. Keys are
mapped correctly. Can you please help?

// note that Hashtable can not be used in native C++, so it has to be
remapped into map class
std::map<std::string, double> input_loan_double_attributes_map;


String* managed_string_key = NULL;
double __gc* key_value;
/* note that enumerator's initial position is not the first, but it
is before the 1st element
in the collection */
IDictionaryEnumerator __gc *hash_enumerator =
input_loan_double_attributes_hash.GetEnumerator();

while (hash_enumerator->MoveNext())
{
managed_string_key = static_cast<String __gc*> (hash_enumerator->Key);

key_value = static_cast<double __gc*>(hash_enumerator->Value);

Console::WriteLine(S"{0}", (*key_value).ToString()); //PRINTS GARBAGE


input_loan_double_attributes_map.insert(std::make_pair(MC::Utils::convert_String_To_string(managed_string_key),

static_cast<double>(*key_value)));

}
 
S

Stan Maydan. from NY

I have resolved it. This is the technique I have used.

String* managed_string_key = NULL;
double temp_value1;
/* note that enumerator's initial position is not the first, but it
is before the 1st element
in the collection */
IDictionaryEnumerator __gc *hash_enumerator =
input_loan_double_attributes_hash.GetEnumerator();

while (hash_enumerator->MoveNext())
{
managed_string_key = static_cast<String __gc*>
(hash_enumerator->Key);

temp_value1 = *(dynamic_cast<__box
double*>(hash_enumerator->Value));

//Console::WriteLine(S"{0}", (temp_value).ToString());


input_loan_double_attributes_map.insert(
std::make_pair(MC::Utils::convert_String_To_string(managed_string_key),
temp_value1));

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top