Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [C++] catturare errori fstream

    Salve,

    come faccio a sapere se una open o write è andata a buon fine con fstram?

    ad esempio:

    codice:
    std::stream file;
    file.open();
    file.write();
    come catturo l'eventuale risposta dato che le funzioni non ritornano?

    grazie
    Alla batteria dai retta ballA

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    codice:
    std::stream file;
    file.open();
    
    if (file.good() ) 
    
    file.write();
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  3. #3
    O, più semplicemente:
    codice:
    if(file)
    {
        // Lo stream è in buono stato
    }
    Volendo poi si può dire agli stream di sollevare eccezioni in caso di errore (link).
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.