Print all the vector by C ++ screen

1

Good evening friends. I have never considered this operation and I do not know how to solve it, it turns out that I have a vector to which I have done a series of operations but I need to verify that all of them are fine. The only way I can think of was to print this vector on the screen and buy them with the original solution. The problem is that when you return it on the screen it is cut in half and I can not do it

cout << "Principio" << endl;
for (i = 0; i < 756; i++)
{
    cout << vector[i] << " Numero " << i+1 << endl;
}
cout << auxi << endl;

    
asked by Alvaro 13.04.2017 в 23:53
source

2 answers

1

Implement a pause

If the problem is that you want to read everything without being erased, you can place a line counter and a pause after a few lines

cout << "Principio" << endl;
int contador = 0;
for (i = 0; i < 756; i++)
{
    contador++;
    cout << vector[i] << " Numero " << i+1 << endl;
    if (contador >= 50) // lee 50 lineas
    { 
         contador = 0;
         while(getchar()!='\n'); // espera a que pulses enter
    }
}
cout << auxi << endl;

Compare 2 files

I really do not know if it's your case, but I leave it here just in case; but if you dump all the solution in a file as suggested by @Genarito and you have another file with the solution you can make a program that compares both files, and print the different values.

#include <iostream>
#include <string>
#include <fstream>

int main()
{
    std::ifstream a;
    std::ifstream b;
    a.open("salida.txt");
    b.open("otro_archivo.txt");
    std::string str1;
    std::string str2;
    while (!a.eof())
    {
        a >> str1;
        b >> str2;
        if (str1.compare(str2)!=0) std::cout << str1 << std::endl;
    }
}

Of course, this only works if you have another file with which to compare.

Greetings

    
answered by 14.04.2017 в 05:19
1

That's because the console buffer was full, you could redirect the standard output to a text file by console:

./tuProgramaCompilado > salida.txt

Or write the values to a file directly from the code:

ofstream miArchivoDeTexto; // Declaro el archivo
miArchivoDeTexto.open ("salida.txt"); // Pongo una ruta
miArchivoDeTexto << "Principio" << endl;
for (i = 0; i < 756; i++)
{
    miArchivoDeTexto << vector[i] << " Numero " << i+1 << endl; // Escribo en el archivo
}
miArchivoDeTexto << auxi << endl;
miArchivoDeTexto.close(); // Cierro el archivo

And now, you can see the entire list in the file salida.txt . I hope I have been helpful.

Greetings!

    
answered by 14.04.2017 в 00:02