Hi to all,

i want to save an array of tchar with his value in the map, as std::map<TCHAR [100], int> word;
but when i say

insert(pair<TCHAR [100],int>(text,1))

the error is: cannot specify explicit initializer for arrays...


Why????

Recommended Answers

All 5 Replies

Did you try pointers? insert(pair<TCHAR*,int>(text,1))

Did you try pointers? insert(pair<TCHAR*,int>(text,1))

yes i tried but the map unordered...

yes i tried but the map unordered...

this method not work...

It's possible to save an array of TCHAR as TCHAR text[100] in a map?
I obtain the text from the edit box...

you need to post the code you have that shows how you are getting the text from the edit box and how it adds text into the map. Is each map entry a unique character buffer or are you using the same buffer for each entry into the map.

Here is an example that works with standard console c++.

int main()
{
    map<TCHAR*,int> theList;
    TCHAR text1[100] = _TEXT("Hello World");
    TCHAR text2[100] = _TEXT("DaniWeb C++ Forums");
    theList.insert(pair<TCHAR*,int>(text1,1));
    theList.insert(pair<TCHAR*,int>(text2,2));

    map<TCHAR*,int>::iterator it = theList.begin();
    cout << (*it).first << "\n";
    it++;
    cout << (*it).first << "\n";
    
}

you need to post the code you have that shows how you are getting the text from the edit box and how it adds text into the map. Is each map entry a unique character buffer or are you using the same buffer for each entry into the map.

Here is an example that works with standard console c++.

int main()
{
    map<TCHAR*,int> theList;
    TCHAR text1[100] = _TEXT("Hello World");
    TCHAR text2[100] = _TEXT("DaniWeb C++ Forums");
    theList.insert(pair<TCHAR*,int>(text1,1));
    theList.insert(pair<TCHAR*,int>(text2,2));

    map<TCHAR*,int>::iterator it = theList.begin();
    cout << (*it).first << "\n";
    it++;
    cout << (*it).first << "\n";
    
}

Thank you for the help...

Yes, I get the text from a unique buffer. After press the button, start a method that, with GetDlg store the text in a buffer called text and then store it in a map... This is my code:

void MyClass::aggiorna_db() {

       //Get the text from editbox and save in a temp, defined as
      // TCHAR tempo [100]
	GetDlgItemText(handle, ID_EDIT, temp, MAXTEXT);

     //Here I check if the text is in the map, in this case I increment the
     // the second field of the map
    
     //Also, inter new item in the map
     db.insert(pair<const TCHAR*,int>(temp,1));

This code is called for every submit the text with the button click.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.