vector can't display full size

Displays only part of the vectors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  #include <iomanip>
#include <iostream>
#include <vector>
#include <math.h>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

vector<int>   source;
vector<double>  square;
typedef vector<int>::size_type vi_t ;

int main()
{

    for(int i = 0; i < 1000 ; i++)
    {
        source.push_back(i);
        square.push_back(sqrt(i));
    }

    for(vi_t i = 0; i < 1000 ; i++)
        cout << source[i] <<std::setw(20) << square[i] << endl;


}

It supposed to display from vector[0] to vector[999] .total 1000 elements per column .
but actually it only displays from vector[704] to vector[999]
What's wrong with my code ? There is no compile error either ...

I am using the newest version CodeBlocks
Last edited on
I'm betting that your console isn't storing all of the history (I'm guessing it stores ~300 lines). Try piping the output to a file and looking at it that way, or waiting every 100 or so lines.
It displays them all, but your console only keeps so many lines to display. Write your output to a file instead if you need to see it all.
Okay ,I will have a try , and let you know , I don't know how to output file in C++ ,hope it will be same as in C ...
1
2
3
4
5
6

    std::ofstream myfile;
    myfile.open ("Acceleratedcpp.txt");

    for(vi_t i = 0; i < 1000 ; i++)
        myfile << source[i] <<std::setw(source.size()/100) << square[i] << endl;


It works !
Thanks !
But
Why didn't the console display them all ?
What if I want display them all ?
What's the theory behind the scene ?
You can't put 2 liters of water in a 1 liter bottle. You can't display a thousand lines in a screen that's 25 lines tall. If you need to display more at once then you can't use the console. It's as simple as that.
closed account (E0p9LyTq)
The console did display every line of text, the earlier lines just were pushed out of the console buffer by the later lines.

If you want a quick way to write your output to a file simply redirect it.

Open a console window, and execute your program, for example:

myprogram.exe > test.txt
Topic archived. No new replies allowed.