online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <fstream> using namespace std; // Clase derivada de "exception" para manejar excepciones // de copia de ficheros. class CopiaEx: public exception { public: CopiaEx(int mot) : exception(), motivo(mot) {} const char* what() const throw(); private: int motivo; }; const char* CopiaEx::what() const throw() { switch(motivo) { case 1: return "Fichero de origen no existe"; case 2: return "No es posible abrir el fichero de salida"; } return "Error inesperado"; } // (1) void CopiaFichero(const char* Origen, const char *Destino); int main() { char Desde[] = "excepcion.cpp"; // Este fichero char Hacia[] = "excepcion.cpy"; try { CopiaFichero(Desde, Hacia); } catch(CopiaEx &ex) { cout << ex.what() << endl; } // (2) return 0; } void CopiaFichero(const char* Origen, const char *Destino) { unsigned char buffer[1024]; int leido; ifstream fe(Origen, ios::in | ios::binary); if(!fe.good()) throw CopiaEx(1); // (3) ofstream fs(Destino, ios::out | ios::binary); if(!fs.good()) throw CopiaEx(2); // (4) do { fe.read(reinterpret_cast<char *> (buffer), 1024); leido = fe.gcount(); fs.write(reinterpret_cast<char *> (buffer), leido); } while(leido); fe.close(); fs.close(); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue