hi,
I am facing problem with pushback() method in Vectors. I am getting
compilation errors when I am using pushabck() in the following
program. I am pasting the code here
/****************************************/
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
class Moving_Average{
public:
std::vector<double> forecast;
// vector<double>forecast;
public:
Moving_Average(int size) {
cout<<" IN size "<<endl;
forecast.resize(size);
cout<<" Out sized "<<endl;
}
void calculate(double *da,int time) {
/* This function is merely copying the elements of vector "data" into
vector "forecast"
*/
for(int i=0;i<time;i++) {
forecast.pushback(*(da+i)); // I am facing problem here
// ^^^^^^^^
}
}
void prasint(int time) {
for(int i=0;i<time;i++) {
cout<<"asd "<<forecast[i]<<endl;
}
}
};
int main()
{
int periods;
cout<<"Enter the no.of periods of historic data"<<endl;
cin>>periods;
vector<double>data(periods);
for(int i=0;i<periods;i++) {
cout<<"Enter data for period --> "<<i<<" ";
cin>>data[i];
}
Moving_Average MA(periods);
MA.calculate(data.begin(),periods);
MA.prasint(periods);
}
/************************************************** *********/
When I used pish_back() in place of pushback(), i didnt get any
compilation errors.But, I am not getting proper output. In the above
program I am copying
the elements of vector 'data' (i.e da) to vector forecast.Here is the
sample out put
/******************************/
Enter the no.of periods of historic data
3
Enter data for period --> 0 1
Enter data for period --> 1 2
Enter data for period --> 2 3
IN calc value is -->1
Out of cal value is -->2
Out of cal value is -->3
Out of cal
in print
asd 1.88323e-307
asd 1.88323e-307
asd 1.88323e-307
/************************************************/
Can somebody tell me what is the difference between pushback() and
push_back()? Is there any better method to store values in vectors
other than this?
Thanks,
Chandrashekar