Why I cannot jump out of a for loop?

I got code like this:

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 <iostream>
#include <vector>


using namespace std;

const long   nx(3);
const long   ny(3);
const long seal(-1);

long TotP(0);
class pore {
public:
	double P;
	long T[4];
    pore() {
    	for(size_t i=0; i<4; i++) T[i]=seal;
    };
};
vector<pore> por;
int main() {
	for(vector<vector<long> >::size_type ix=0; ix<=nx; ++ix) {
		for(vector<long>::size_type iy=0; iy<=ny; ++iy) {
			por.push_back(pore());
			cout<<TotP<<endl;
	}}
	cout<<"Finish loop"<<endl;
return 0;
}


I can print out all those TotP, but cannot get Finish loop print out, why? If I put any statement below, which seems won't be executed, it is like it never jump out from the loop and die inside. Please teach, thanks.
Last edited on
what are TotP and psat? where have you defined them?
plus: what is dot
sorry, I defined it in my original problem, and now I want to simplify the problem and deleted them.
¿and what is `TotP' now?
please make sure that your code does reproduce your issue
Last edited on
sorry, TotP is defined;
I guess it's the good old problem that the console closes (from IDE) before the output appears.

See:
http://www.cplusplus.com/articles/iw6AC542/
Segmentation fault (core dumped)

This is the extra message I got, except my defined,when not using IDE, is this the problem you said?
Why don't you use std::vector for long T[4] ?
You need to learn how to use the debugger. I did not see anything wrong with the posted code. Stepping into the code with debugger will tell you a lot.

The following makes no sense to me since you really don't create a 2D vector, but I don't see how it would cause a seg fault. It's just goofy. You might as well setup a single loop of x times y.
for(vector<vector<long> >::size_type ix=0; ix<=nx; ++ix)

pore constructor looks okay, but it would be better to use std::fill.

std::fill(T, T + 4, seal);
Topic archived. No new replies allowed.