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

  • Home
  • SEARCH
  • 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 1032045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:01:30+00:00 2026-05-16T14:01:30+00:00

I am trying to create a map using two arrays. Here is the code:

  • 0

I am trying to create a map using two arrays. Here is the code:

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <iterator>
#include <string>
using namespace std;
using std::transform;
int main(){
    const char* word[]={"A","B","C","D","E"};
    const char * clue[]={"a","b","c","d","e"};
    map<string,string>dictionary;
    map<string,string>::iterator it;
    transform(word, word+sizeof(word)/sizeof(word[0]), clue,
              inserter(dictionary,dictionary.end()), make_pair<string,string>);

    for (it=dictionary.begin(),it!=dictionary.end();it++)
        cout<<it->first<< " "<<it->second<<endl;
    return 0;
}

But here are the mistakes:

1>------ Build started: Project: map_array, Configuration: Debug Win32 ------
1>Build started 8/21/2010 4:27:25 PM.
1>PrepareForBuild:
1>  Creating directory "c:\users\david\documents\visual studio 2010\Projects\map_array\Debug\".
1>InitializeBuildStatus:
1>  Creating "Debug\map_array.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  map_array.cpp
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_OutTy (&)[_OutSize]' from 'std::insert_iterator<_Container>'
1>          with
1>          [
1>              _Container=std::map<std::string,std::string>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1293) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InIt2,_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_OutTy (&)[_OutSize]' from 'std::insert_iterator<_Container>'
1>          with
1>          [
1>              _Container=std::map<std::string,std::string>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1279) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2914: 'std::transform' : cannot deduce template argument as function argument is ambiguous
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::insert_iterator<_Container>'
1>          with
1>          [
1>              _Container=std::map<std::string,std::string>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1267) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2914: 'std::transform' : cannot deduce template argument as function argument is ambiguous
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::insert_iterator<_Container>'
1>          with
1>          [
1>              _Container=std::map<std::string,std::string>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1249) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2780: '_OutTy *std::transform(_InIt,_InIt,_OutTy (&)[_OutSize],_Fn1)' : expects 4 arguments - 5 provided
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1127) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(16): error C2780: '_OutIt std::transform(_InIt,_InIt,_OutIt,_Fn1)' : expects 4 arguments - 5 provided
1>          c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1111) : see declaration of 'std::transform'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(20): error C2143: syntax error : missing ';' before ')'
1>c:\users\david\documents\visual studio 2010\projects\map_array\map_array\map_array.cpp(20): error C2451: conditional expression of type 'std::_Tree_iterator<_Mytree>' is illegal
1>          with
1>          [
1>              _Mytree=std::_Tree_val<std::_Tmap_traits<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>,false>>
1>          ]
1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.19
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How do I fix this problem?


EDITED
I have tried another version of the solution to this problem (using by the Internet and C++ sites), and I have found a way to solve this problem like this

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <iterator>
#include <string>
using namespace std;

template<typename KeyType, typename ValueType, int N>
class mapmaker
{
    std::pair<KeyType, ValueType> (&table)[N];
    const KeyType (&keys)[N];
    const ValueType (&vals)[N];

    template<int pos> void fill_pair()
    {
        table[pos].first = keys[pos];
        table[pos].second = vals[pos];
        fill_pair<pos-1>();
    }

    template<> void fill_pair<0>()
    {
        table[0].first = keys[0];
        table[0].second = vals[0];
    }

    public:
        mapmaker( std::pair<KeyType, ValueType> (&t)[N], const KeyType (&k)[N], const ValueType (&v)[N] )
            : table(t), keys(k), vals(v)
        {
            fill_pair<N-1>();
        }
};

template<typename KeyType, typename ValueType, int N>
std::map<KeyType,ValueType> make_map(const KeyType (&keys)[N], const ValueType (&vals)[N])
{
    std::pair<KeyType, ValueType> table[N];
    mapmaker<KeyType, ValueType, N>( table, keys, vals );
    return std::map<KeyType, ValueType>(table, table+N);
}

int main(){
    static const string word[]={"A","B","C","D","E"};
    static const string clue[]={"a","b","c","d","e"};
    static map<string,string>dictionary=make_map(word,clue);
    map<string,string>::iterator it;
    //transform(word,word+sizeof(word)/sizeof(word[0]),clue,clue,inserter(dictionary,dictionary.end()));

    for (it=dictionary.begin();it!=dictionary.end();it++)
        cout << it->first << " " << it->second << endl;
    //cout<<dictionary.size();
    return 0;
}
  • 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-16T14:01:30+00:00Added an answer on May 16, 2026 at 2:01 pm

    The code looks valid, and it compiles with GCC, after changing the syntax error in your for loop (the comma should be a semicolon after the initial part).

    Note that C++03 compilers are not necessarily required to correctly get a function pointer with make_pair<string,string>. Only C++0x allows directly getting the address of a function template specialization without casting but merely giving a template argument list, but usually C++03 compilers backpart that feature and implement it even in C++03 mode. But i think it is unlikely that this is the source of your problem here.

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

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I guess you want to create a NSMutableArray of NSMutableArrays:… May 16, 2026 at 11:28 pm
  • Editorial Team
    Editorial Team added an answer http://jsfiddle.net/YuCQR/1/ Too long to post entirely, but this should work… May 16, 2026 at 11:28 pm
  • Editorial Team
    Editorial Team added an answer Tried with the nlm() function already? Don't know if it's… May 16, 2026 at 11:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i'm just trying to create this little simulator. in a gui, i have two
I am trying to create a type of mind mapping software that runs on
I'm trying to setup a bidirectional localConnection (LC) between two flash objects on the
I need to be able to, using either V2 OR V3 (preferably 3), create
I have two PDFs that are made on the fly using Prawn PDF. The
This is mostly for educational purposes. I'm trying to create the InputMapper class, which
I'm trying to generate a Google Map based off of results from a database.
I am using the EzAPI to create a dataflow with FlatFile Source public class
I'm trying to map myexisting database by Fluent NHibernate I get error: The element
I am trying to figure out the memory consumption by my (C++) program using

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.