Skip to content

Tutorial — ejercicio-archivo

Learn by programming: follow each step, write your own code, then apply it to the course assignment.

What you will build

Read a text file and write another with uppercase content.

  1. 1

    Open input file

    Use `std::ifstream` and verify the file exists before reading.
    
    								std::ifstream in("entrada.txt");
    if (!in) {
        std::cerr << "No se pudo abrir entrada.txt\n";
        return 1;
    }
    							
  2. 2

    Convert to uppercase

    You can use `` `toupper` per character or `` algorithms.
  3. 3

    Write output file

    `std::ofstream` with a different name (e.g. `salida.txt`). Close streams when done.
  4. 4

    Test with sample file

    Create `entrada.txt` with lowercase and verify `salida.txt`.

Back to tutorial page