I admit that I am not an expert in C++. The following solution is modified from my java version. The same algorithm works in Java. So it must be some simple mistake in my C++.

Thanks for your help. I have labeled the problematic line.

```
class Solution {
public:
int largestRectangleArea(vector<int> &height) {
if (height.size()==0) return 0;
stack<int> index;
index.push(-1);
int result=0;
int top;
for (int i=0;i<height.size();i++){
//Start calculate the max value
while (index.top()>-1){
if (height.at(index.top())>height.at(i)){
top=index.pop(); //This line always has problem
result=max(result,height.at(top)*(i-1-index.top()));
}else break;
}
index.push(i);
}
while(index.top()!=-1){
top=index.pop();
result=max(result,height.at(top)*(height.size()-1-index.top()));
}
return max;
}
};
```