Containers und List



  • Hallo ,
    ich habe 2 list / Container definiert

    //Datastruktur.h
    
    list <int> Userid;
    list <COleDateTime> m_lDatum;
    

    und dann habe ich die Listen bzw. Conatiners wie unten ausgefüllt

    //Datastruktur.cpp
    
    	try
    	{
    		rH.m_strFilter.Format(_T("[MaschineNr] = %d"), m_iMaschineId);
    
    		rH.Open(CRecordset::snapshot, NULL, CRecordset::readOnly); 
    
    		while (!rH.IsBOF() && !rH.IsEOF())
    		{
    			if(rH.m_Datum>=m_DatumV && rH.m_Datum<=m_DatumB)
    			{
    
    				Userid.push_back(rH.m_Hs_UserID);//Userid wird ausgefüllt
    				m_lDatum.push_back(rH.m_Datum);//m_lDatum wird ausgefüllt
    
    			}
    
    			rH.MoveNext();
    		}
    	}
    	catch(CDBException *e)
    	{
    		e->Delete();
    	}
    

    und dann wollte ich die Ausgefüllte Listen/Containers bzw. die Werte die drin gespeichert sind, auf einem Dialog zeigen.

    //Dialog.cpp
    
    	list<int>::iterator userIdIt	= m_ptr->Userid.begin();
    	list<COleDateTime>::iterator DatumIt	= m_ptr->m_lDatum.begin();
    
    //1) Diese Teil funktioniert ganz normal ich sehe alle werte auf meinem Dialog
    	while (userIdIt != m_ptr->Userid.end())
    		{
    			CString sStr;
    			sStr.Format(_T("%d"), *userIdIt);
    			pDC->TextOut(x_1,y_1,sStr);
    
    			y_1=y_1+20;
    
    			userIdIt++;
    		}
    //2)Aber leider hier sehe ich nichts
    	while (DatumIt != m_ptr->m_lDatum.end())
    		{
    			CString sStr2;
    			sStr2.Format(_T("%A,%B,%y"), *DatumIt);
    			pDC->TextOut(x_1+370,y_2,sStr2);
    
    			y_2=y_2+20;
    
    			DatumIt++;
    		}
    

    wie oben ich kommentiert habe, bei der erste While schleife funktioniert alles aber bei der zweite while schleife klappt es irgendwie nicht. Eigentlich sind die beide Containers gleich , nur Typs sind unterschiedlich. Kann mir bitte jemand helfen..
    Danke


  • Mod

    CString sStr2; 
                sStr2.Format(_T("%A,%B,%y"), *DatumIt);
    

    Kann doch nicht gehen.
    Du musst COleDateTime::Format aufrufen und nicht CString::Format!



  • while (DatumIt != m_ptr->m_lDatum.end())
    		{
    			COleDateTime sStr2;
    			sStr2.Format(_T("%A,%B,%y"), *DatumIt);
    			pDC->TextOut(x_1+370,y_2,sStr2);
    
    			y_2=y_2+20;
    
    			DatumIt++;
    		}
    

    Es geht trotzdem nicht



  • for(int i=0;i<m_ptr->m_vDatum.size();i++)
    	{
    			CString sStr;
    			sStr.Format(_T("%A,%B,%d,%y"), m_ptr->m_vDatum);
    			pDC->TextOut(x_1+370,y_2,sStr[i]);
    			y_1=y_1+20;
    	}
    

    Wenn ich es nicht mit list sondern mit Vektor wie oben probiere, dann bekomme ich ausnahmefehler,...



  • DatumIt is doch vom Type COleDateTime und von dem mußt du das format aufrufen

    while (DatumIt != m_ptr->m_lDatum.end())
            {
                CString sStr2 = DatumIt->Format(_T("%A,%B,%y"));
                pDC->TextOut(x_1+370,y_2,sStr2);
    
                y_2=y_2+20;
    
                DatumIt++;
            }
    

    zumindest so in der art, ob das jetzt genau so läuft hab ich net getestet.



  • Vielen vielen dank,
    Es hat wunderbahr geklappt..


Anmelden zum Antworten