This code gives a compile-error on Topcoder. On code::blocks, it compiles with 0 errors and 0 warnings, the vector is printed, but it exits with a non-zero value, that causes windows to display “InterestingDigits.exe has stopped working”. Any help on this..?
#include<iostream>
#include<vector>
using namespace std;
class InterestingDigits
{
public:
vector <int> digits(int base)
{
vector<int> v;
for(int i=2; i<base; i++)
if(base%i==1)
v.push_back(i);
for(int i=0; i<v.size(); ++i)
cout<<v[i]<<" ";
cout<<endl;
}
};
int main()
{
int base;
cin>>base;
InterestingDigits id;
id.digits(base);
return 0;
}
It seems that your method digits() should return a value, a vector < int >.
Maybe adding a “return v;” at the end?