Probleme beim Lesen aus Datei



  • Hallo

    Ich habe mal wieder ein Problem. Ich versuche gerade Daten in eine Datei zu schreiben und diese dann wieder zu lesen.

    Schreiben mach ich so:

    m_myfilein.open("d:\\HighScore.dat");
    if(!m_myfilein)
    	MessageBox("hat nicht geklappt");
    else 
    {
    	MessageBox("hat geklappt");
    	for(int i=0;i<10;i++)
    	{
    		m_StartDialog.m_aiAusgabeHScr[i]=0;
    		m_myfilein<<m_StartDialog.m_aiAusgabeHScr[i];
    	}
    	for(int i=0;i<10;i++)
    	{
    		m_StartDialog.m_astrAusgabeName[i]="unbekannt";
    		m_myfilein<<m_StartDialog.m_astrAusgabeName[i];
    	}
    }
    

    und das klappt auch einwandfrei. Wenn ich diese Daten nun auslesen will, bekomme ich eine Fehlermeldung aus der ich nicht schlau werde. Ich versuche die Daten so zu lesen:

    m_myfileout.open("d:\\HighScore.dat");
    std::string strWort[10];
    if(!m_myfileout)
    	MessageBox("Highscoredatei konnte nicht geöffnet werden");
    else
    {
    	MessageBox("hat geklappt");
    	for(int i=0;i<10;i++)
    		m_myfileout>>m_StartDialog.m_aiAusgabeHScr[i];
    	for(int i=0;i<10;i++)
    		m_myfileout>>strWort[i];
    }
    

    wenn ich das so mache meckert mein Rechner:

    error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

    Ich habe das eigentlich aber schon einmal so probiert und da hat es funktioniert. Wahrscheinlich bin ich blind.

    Am liebsten wäre es mir aber ich könnte es so lösen:

    m_myfileout.open("d:\\HighScore.dat");
    std::string strWort[10];
    if(!m_myfileout)
    	MessageBox("Highscoredatei konnte nicht geöffnet werden");
    else
    {
    	MessageBox("hat geklappt");
    	for(int i=0;i<10;i++)
    		m_myfileout>>m_StartDialog.m_aiAusgabeHScr[i];
    	for(int i=0;i<10;i++)
    		m_myfileout>>m_StartDialog.m_astrAusgabeName[i];
    }
    

    Dann bekomme ich aber folgende Fehlermeldung:

    error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CString' (or there is no acceptable conversion)

    Ihr habt doch sicher eine Lösung?

    Danke chrische



  • hallo mit getline
    string line;
    getline(m_myfilein,line);
    cout<<line;

    getline liest eine ganze zeile aus.



  • error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CString' (or there is no acceptable conversion)
    

    Glaube da gibt's nen bug im VC++
    versuche einmal

    m_myfileout>>(const char*)m_StartDialog.m_aiAusgabeHScr[i];
    

    eine conversion von CString -> const char * gibts auf jeden fall.
    Kurt



  • Hallo

    Danke für die Antworten . Ich habe es jetzt mal so probiert, wie oben beschrieben:

    for(int i=0;i<10;i++)
                m_myfileout>>(const char*)m_StartDialog.m_astrAusgabeName[i];
    

    Leider bekomm ich dann folgende Fehlermeldung:

    error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>::PCXSTR' (or there is no acceptable conversion)
    with
    [
    BaseType=char,
    t_bMFCDLL=true
    ]

    Was kann man den da machen?

    chrische



  • ****hochschieb****

    weil ich nicht weiter weiß.

    chrische


Anmelden zum Antworten