I write a function, which fill vtwo dimensional vector like a matrix, and its work. Then i read function for output and there is the problem. When for index i input even number( i think that is the right word - mean "number who %2==0 i c++ language") the program output rightly and then close unexpectly. With odd numbers it works nice.
there is the code:
Here's the problem: on line 16, you're checking that i is lower than t[i].size(). If i is at one moment >=t.size() (which will always happen at the ideal end of the loop), that comparison is going to throw an exception, because you're trying to access an element beyond the end of the vector. What you really want to do is check with t.size(), not t[i].size(). It was working with odd numbers probably because of the code your brain-dead compiler generated. MinGW generates code that crashes no matter what the input is.
You have another error on line 20: n is not a member of int. I have no idea how your compiler didn't complain about this.
Also, void main() is non-standard.
I fill the vectors like a square, this means that t.size() is equal to t[i].size(), becouse its square and each borders is equals. And i write it with even numbers it dont works but with odd numbers works.
I understood what you're doing perfectly.
For each valid t[i[b][/b]], t[i].size is indeed equal to t.size().
Let's assume that the user entered 10. that means that all valid t[i] are t[0..9]. It order to check after the last iteration, when i==10, whether to continue, you need to check that (i=10)<t[(i=10)].size(). Since the last valid t[i] is t[9], when you try to access t[10] to check its size, the vector class throws an exception and the program crashes.
The correct way is to always check the size of the vector you're currently traversing, even if you know that the inner vectors will be of the same size.
The fact that it works [i]for you[/i] with odd numbers is a coincidence. I compiled it and it crashed no matter what my input was.
Well i always be used the current size of the vector with i works.
But don't understand what means
"Also, void main() is non-standard."
Is has another way to write void main() ? Or must return this:
Is this can corrupt a problem, or this is a good style of writing programs. Becouse in school always we write main functions with void and anyone dont tell me that is wrong
It's always better to adhere to the standard. The fact that some compilers allow void main() doesn't mean that all do. If your teacher doesn't tell you anything about using void main(), then I don't think s/he's a very good teacher.