c++ - Making multiple vectors from one vector of random doubles -
i generating vector of 20,000 random numbers (doubles) , like, in addition putting number in vector, called here, copy numbers between 0.0 , 0.1 separate vector. when try this, compiler (latest g++ version) gives me these errors:
"error: request member 'begin' in 'r0', of non-class type 'std::vector<double>()' (it0=r0.begin(); it0!=r0.end();++it0)" "error: request member 'end' in 'r0', of non-class type 'std::vector<double>()' (it0=r0.begin(); it0!=r0.end();++it0)" "error: request member 'emplace_back' in 'r0', of non-class type 'std::vector<double>()' r0.emplace_back(a[i]);"
i relative novice in c++, thought vector data structure had methods/member functions called .begin() , .end() access using iterators. seems me compiler doesn't see vector vector? i'm not sure, below did:
i have linked: iostream, cmath, fstream, time.h, cstdlib, vector, stdio.h, cstdio, iomainip, algorithm (in order)
here code have now:
int main() { double n=20000; std::vector<double> a(n+1); std::vector<double> r0(); std::vector<double>::iterator it0; std::srand((unsigned)time(0)); for(double = 0; i<(n+1); ++i) { double high = 1.0, low = 0.0; a[i]=((double) rand()/(static_cast<double>(rand_max) + 1.0))*(high - low)+low; for(it0=r0.begin(); it0!=r0.end(); ++it0) { if(0.0<=a[i] && a[i]<0.1) { //note:post-incrementing creates unnecessary temporary iterator rand1.emplace_back(a[i]); count0++; } } } return 0; }
the point of place of numbers in vector bins of size 0.1 each, starting 0.0, , plot them in histogram using gnuplot assess uniformity of random numbers (generated using pseudorandom number generator comes linux mint). also, wanted ask advantages of .emplace_back() on .push_back(). thank help! appreciate @ loss i'm doing wrong.
std::vector<double> r0();
this parsed function taking no argument , returning std::vector<double>
. called most vexing parse error. there error in loop. together, should read:
std::vector<double> r0; for( int = 0; < n+1; ++i) { if(0.0<=a[i] && a[i]<0.1) { //... } }
Comments
Post a Comment