Click here to Skip to main content
15,898,770 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CDateTimeCtrl in MFC - How to Use? Pin
David Crow17-Aug-09 4:25
David Crow17-Aug-09 4:25 
GeneralRe: CDateTimeCtrl in MFC - How to Use? Pin
Larry Mills Sr19-Aug-09 8:07
Larry Mills Sr19-Aug-09 8:07 
QuestionRe: CDateTimeCtrl in MFC - How to Use? Pin
David Crow19-Aug-09 8:29
David Crow19-Aug-09 8:29 
AnswerRe: CDateTimeCtrl in MFC - How to Use? Pin
Larry Mills Sr19-Aug-09 10:26
Larry Mills Sr19-Aug-09 10:26 
GeneralRe: CDateTimeCtrl in MFC - How to Use? Pin
David Crow19-Aug-09 10:30
David Crow19-Aug-09 10:30 
QuestionUse a map as a source of data Pin
Waldemar Ork16-Aug-09 3:18
Waldemar Ork16-Aug-09 3:18 
AnswerRe: Use a map as a source of data Pin
«_Superman_»16-Aug-09 19:19
professional«_Superman_»16-Aug-09 19:19 
GeneralRe: Use a map as a source of data Pin
Waldemar Ork17-Aug-09 5:53
Waldemar Ork17-Aug-09 5:53 
Dear Superman,
I have thought out what you said last night and tried to take your advice practically, but somehow it doesn't work. (I also came to a conclusion how little I know about iterators. I promise to learn more about them.)The code map::find consists of two parts. And to be honest I'm not interested in finding one or two vectors in the map (this is in the first part of the code). My task is to find all the vectors matching the string output keys.(if I understood it correctly, this would be the second part about using a dereferenced iterator, but I'm not sure). The fact is I got completely lost in those damn iterators!
Here's what I wrote with header files to compile and run it.
cpp. first-
#include "IndexCombination.h"

using namespace stdcomb;


void CIdxComb::Init( unsigned int SetSize, unsigned int CombSize   )
{
     // Assign CombSize
     ////////////////////////
     if( CombSize == 0 )
          CombSize = 1;

     m_ArrSize = CombSize;
     m_LastIdx = CombSize - 1;

     // Assign SetSize
     ////////////////////////
     if( SetSize == 0 )
          SetSize = 2;

     if( CombSize > SetSize )
          CombSize = SetSize;
    
     m_SetSize = SetSize;
     m_LastSetIdx = SetSize - 1;
}


bool CIdxComb::SetSizes( unsigned int SetSize, unsigned int CombSize )
{
     if( SetSize == 0 )
          return false;

     if( CombSize == 0 )
          return false;

     if( CombSize > SetSize )
          return false;
    
     m_ArrSize = CombSize;
     m_LastIdx = CombSize - 1;

     m_SetSize = SetSize;
     m_LastSetIdx = SetSize - 1;

     return true;

}


bool CIdxComb::GetNextComb( std::vector<unsigned int> &vi )
{
    
     // Check if the last element is at the end
     if( vi[m_LastIdx] == m_LastSetIdx )
     {
          if( m_ArrSize == 1 ) // Completed
               return false;

          // Check if the subsequent elements(counted from back)
          // is also at their subsequent positions
          //////////////////////////////////////////////////////
          bool Completed = true;
          // Incomplete Index, init value not used
          unsigned int IncompIdx = m_LastIdx - 1;
         
          bool FirstIdx = false;
          unsigned int ArrIdx = m_LastIdx - 1;

          unsigned int SetIdx = m_LastSetIdx - 1;
         
          while( !FirstIdx )
          {
               if( vi[ArrIdx] != SetIdx )
               {
                    Completed = false;
                    IncompIdx = vi[ArrIdx] + 1;
                    break;
               }

               if( SetIdx )
                    --SetIdx;
         
               if( !ArrIdx )
                    FirstIdx = true;
               else
                    --ArrIdx;
                   
          }

          if( Completed )
               return false;
          else
          {
               for( unsigned int i=ArrIdx; i<=m_LastIdx; ++i, ++IncompIdx )
               {
                    vi[i] = IncompIdx;
               }
          }
    
     }
     else if ( vi[m_LastIdx] < m_LastSetIdx )
     {
          (vi[m_LastIdx])++;
     }
     else // bigger than the m_LastIdx! Impossible!
     {
          return false;
     }
    
     return true;
}

h.next-
//Index Combination.h
#include <vector>

#ifndef _INDEXCOMBINATION_H_
#define _INDEXCOMBINATION_H_

namespace stdcomb
{


class CIdxComb
{
public:
     // Constructor
     CIdxComb()
     {
          Init( 2, 1 );
     };

     CIdxComb( unsigned int SetSize, unsigned int CombSize )
     {
          Init( SetSize, CombSize );
     };
    
    
     // Destructor
     ~CIdxComb() {};


     void Init( unsigned int SetSize, unsigned int CombSize );

     bool SetSizes( unsigned int SetSize, unsigned int CombSize );

     bool GetNextComb( std::vector<unsigned int> &vi );

protected:
     unsigned int m_ArrSize;
     unsigned int m_LastIdx;
    
     unsigned int m_SetSize;
     unsigned int m_LastSetIdx;

};


}
#endif // _INDEXCOMBINATION_H_
#include <vector>
and finally what I tried to do-
// IntComb.cpp : Defines the entry point for the console application.


#include "IndexCombination.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <sstream>
#include <utility>
#include <list>
using namespace std;
using namespace stdcomb;
template <class K, class V>
class key_equals {
   private:
      K key;
   public:
      // constructor (initialize key to compare with)
      key_equals (const K& k)
      : key(k) {
      }
      // comparison
      bool operator() (pair<const K, V> elem) {
            return elem.first == key;
      }
};
         
int main(int argc, char* argv[])
{
     
      int ia11[30] = {3,9,17,21,24,31,33,36,42,49,
                                 4,8,19,22,28,30,34,39,43,47,
                                 2,6,10,13,14,25,29,37,38,46};
      int ia34[30] ={1,6,12,15,22,27,31,32,41,42
                              ,4,7,14,17,23,30,33,36,45,48
                              ,2,9,13,18,21,26,34,39,44,49};
      int ia72[30] = {3,8,11,18,22,25,36,37,43,46
                              ,1,6,16,17,23,28,35,40,41,44
                              ,2,5,12,19,24,27,31,34,42,49};
      int ia167[30] ={3,4,12,15,21,28,32,39,47,48
                              ,6,9,16,17,29,30,31,38,41,42
                              ,7,8,11,20,26,27,34,35,45,46};
      int ia190[30] = {3,10,11,14,22,23,32,35,43,44
                              ,6,9,16,19,24,29,37,38,45,48
                              ,2,5,13,18,25,30,31,40,41,0};
      int ia21[30] ={ 2,5,16,19,25,30,34,39,45,48,
                                 1,9,12,13,21,24,33,36,44,49,
                                 3,8,15,20,23,26,35,40,43,46};
      int ia64[30] ={6,9,13,20,28,29,33,40,43,48
                              ,2,7,16,19,24,27,31,34,44,47
                              ,5,8,14,17,21,30,32,37,41,46};
      int ia102[30] ={4,9,14,19,22,29,35,38,46,47
                              ,5,8,13,16,21,26,33,40,41,48
                              ,6,7,15,17,28,30,32,39,42,45};
      int ia178[30] ={6,9,15,20,23,24,37,38,42,45
                              ,7,8,16,19,22,25,34,39,43,46
                              ,1,2,17,18,26,29,31,40,47,0};
      int ia180[30] ={1,4,13,18,27,30,33,38,45,46
                              ,2,3,12,15,22,23,39,40,44,47
                              ,8,9,11,17,24,25,32,37,49,0};
                             
     vector<int>via11(ia11,ia11+30);
      vector<int>via34(ia34,ia34+30);
      vector<int>via72(ia72,ia72+30);
      vector<int>via167(ia167,ia167+30);
      vector<int>via190(ia190,ia190+30);
      vector<int>via21(ia21,ia21+30);
      vector<int>via64(ia64,ia64+30);
      vector<int>via102(ia102,ia102+30);
      vector<int>via178(ia178,ia178+30);
      vector<int>via180(ia180,ia180+30);
                   
  

     CIdxComb cb;

     cb.SetSizes(10,6);


     vector<string> vsia;
     vsia.push_back( "ia11" );
     vsia.push_back( "ia34" );
     vsia.push_back( "ia72" );
     vsia.push_back( "ia167" );
     vsia.push_back( "ia190" );
      vsia.push_back( "ia21" );
     vsia.push_back( "ia64" );
     vsia.push_back( "ia102" );
     vsia.push_back( "ia178" );
     vsia.push_back( "ia180" );
     vector<unsigned int> vi(6);

     vi[0] = 0;
     vi[1] = 1;
     vi[2] = 2;
      vi[3] = 3;
     vi[4] = 4;
     vi[5] = 5;
     cout<< vsia[ vi[0] ] << " "
          << vsia[ vi[1] ] << " "
          << vsia[ vi[2] ] << " "
            << vsia[ vi[3] ] << " "
          << vsia[ vi[4] ] << " "
          << vsia[ vi[5] ] << "\n";
     int Total = 1;
     while ( cb.GetNextComb( vi ) )
     {
          // "Do whatever processing you want" - I want to put all the values
          // from the vectors to their 6 elemnts combinations
          {

      map<string,vector<int> > m1;
      map <string,vector<int> > :: const_iterator m1_AcIter, m1_RcIter;
     typedef pair<string,vector<int> > String_Int_Pair;//there has been a change here
     
      m1.insert(make_pair("ia11", via11));
      m1.insert(make_pair("ia34", via34));
      m1.insert(make_pair("ia72", via72));
      m1.insert(make_pair("ia167", via167));
      m1.insert(make_pair("ia190", via190));
      m1.insert(make_pair("ia21", via21));
      m1.insert(make_pair("ia64", via64));
      m1.insert(make_pair("ia102", via102));
      m1.insert(make_pair("ia178", via178));
      m1.insert(make_pair("ia180", via180));
     
      m1_AcIter = m1.end( );
      m1_AcIter--;
      m1_RcIter = m1.find( m1_AcIter -> first );
      cout << m1_RcIter -> second << "." << endl;//The compiler stops here.
            // I don't want only
            //one particular string - representing vector of course - to be copied to output.
            // I've got 210 combinations each of 6 strings. That makes 1260 strings altogether
            // to be identified and filled with vectors values of integer .
           
           
                                         
}    
          cout<< vsia[ vi[0] ] << " "
               << vsia[ vi[1] ] << " "
               << vsia[ vi[2] ] << " "
                << vsia[ vi[3] ] << " "
               << vsia[ vi[4] ] << " "
               << vsia[ vi[5] ] << endl;
          ++Total;
         
     }

     cout<< "\nTotal : " << Total << endl;
    
     system( "pause" );
     return 0;
}

If you could help me, I would be really happy!
Looking forward to hearing from You,
Waldemar
Question╠ How get video card memory size ? ╣ Pin
bzsolt9116-Aug-09 2:21
bzsolt9116-Aug-09 2:21 
AnswerRe: ╠ How get video card memory size ? ╣ Pin
Hristo-Bojilov16-Aug-09 7:45
Hristo-Bojilov16-Aug-09 7:45 
AnswerRe: ╠ How get video card memory size ? ╣ Pin
kilt17-Aug-09 3:06
kilt17-Aug-09 3:06 
AnswerRe: ╠ How get video card memory size ? ╣ Pin
bzsolt9123-Aug-09 4:29
bzsolt9123-Aug-09 4:29 
QuestionHow to cause a CPropertySheet to show a particular page .. [SOLVED] Pin
Ahmed Charfeddine16-Aug-09 1:12
Ahmed Charfeddine16-Aug-09 1:12 
AnswerRe: How to cause a CPropertySheet to show a particular page .. Pin
David Crow16-Aug-09 11:31
David Crow16-Aug-09 11:31 
GeneralRe: How to cause a CPropertySheet to show a particular page .. Pin
Ahmed Charfeddine16-Aug-09 11:41
Ahmed Charfeddine16-Aug-09 11:41 
QuestionError 1008 while using CoCreateInstance Pin
emmmatty115-Aug-09 21:19
emmmatty115-Aug-09 21:19 
QuestionPrint and Print Preview and relation with document view Pin
Amin.Abdi15-Aug-09 19:34
Amin.Abdi15-Aug-09 19:34 
AnswerRe: Print and Print Preview and relation with document view Pin
«_Superman_»16-Aug-09 19:06
professional«_Superman_»16-Aug-09 19:06 
QuestionMouse as an erasing tool Pin
kudlaty7915-Aug-09 10:06
kudlaty7915-Aug-09 10:06 
AnswerRe: Mouse as an erasing tool Pin
Michael Schubert15-Aug-09 13:22
Michael Schubert15-Aug-09 13:22 
AnswerRe: Mouse as an erasing tool Pin
«_Superman_»15-Aug-09 17:41
professional«_Superman_»15-Aug-09 17:41 
GeneralRe: Mouse as an erasing tool Pin
kudlaty7916-Aug-09 3:08
kudlaty7916-Aug-09 3:08 
GeneralRe: Mouse as an erasing tool Pin
Cedric Moonen16-Aug-09 20:13
Cedric Moonen16-Aug-09 20:13 
GeneralRe: Mouse as an erasing tool Pin
kudlaty7916-Aug-09 23:01
kudlaty7916-Aug-09 23:01 
GeneralRe: Mouse as an erasing tool Pin
Cedric Moonen16-Aug-09 23:14
Cedric Moonen16-Aug-09 23:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.