#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
usingnamespace std;
int main(){
int count = 0;
vector<int> c;
while(true){
c.clear();
c.push_back(count); //testing if clear works and if c only contains the latest element
if (count ==99){
cout<<"got here!"<<endl; //not executed
cout<<c[0]<<endl; //also not executed
break;
}
count++;
}
}
My code doesn't run forever, but got here isn't executed.
In function 'int main()': 11:3: error: 'class std::vector<int>' has no member named 'pushback'
That code does not compile, so it's hard to say for certain what the problem is.
When I change pushback to push_back, "got here!" is executed just fine for me.
Are you sure you're posting correct, up-to-date code?
(Also your formatting is frankly atrocious. Please use consistent indentation.)
My code doesn't run forever, but got here isn't executed.
What do you mean by "got here isn't executed"? Do you mean you are not seeing anything printed? Is your console staying open long enough to see the result?
Try using a debugger and putting a break point on line 15...