Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15217

Strange STL vector behavior -- request help

From dakupoto@gmail.com
Newsgroups comp.lang.c++
Subject Strange STL vector behavior -- request help
Date 2012-04-04 00:31 -0700
Organization http://groups.google.com
Message-ID <3258921.1909.1333524687267.JavaMail.geo-discussion-forums@pbcwe9> (permalink)

Show all headers | View raw


Could some C++ guru please provide some hints to this
odd C++ STL vector issue ? 
I have in a class:

private:
   std::vector<double> invect;
   std::vector<double> invect_copy;
   std::vector<double> filtvect;
'invect' gets filled correctly with 64 distinct double
values, as checked with a simple print statement.

Then I have:
 invect_copy = invect;
 invect.clear(); 
 /*for(i = 0; i < MAXELEM; i++) std::cout<<invect_copy[i]<<std::endl; */ 
Here again, the print statement correctly shows the elements added
to 'invect_copy'

Now I wish to read out chunks of data from 'invect_copy' as:
if(invect_copy.size() > 0)
       {
         while(clim + MAXFILTELEM < MAXELEM)
         { 
           for(j = 0; j < MAXFILTELEM; j++) 
           { 
             cind = j + clim;
             tmp = invect_copy.at(cind);
             std::cout<<name()<<" "<<j<<" "<<cind<<" "<<clim<<" "<<tmp<<std::endl;
             filtvect.push_back(tmp);
           }

This time however, I get the same value being for all values
of the index 'cind' as:
mavg 0 0 0 1.80429e+09
mavg 1 1 0 1.80429e+09
mavg 2 2 0 1.80429e+09
mavg 3 3 0 1.80429e+09
mavg 4 4 0 1.80429e+09
mavg 5 5 0 1.80429e+09
mavg 6 6 0 1.80429e+09
mavg 7 7 0 1.80429e+09
mavg 8 8 0 1.80429e+09
mavg 9 9 0 1.80429e+09
mavg 0 1 1 1.80429e+09
mavg 1 2 1 1.80429e+09
mavg 2 3 1 1.80429e+09
mavg 3 4 1 1.80429e+09
mavg 4 5 1 1.80429e+09
mavg 5 6 1 1.80429e+09
mavg 6 7 1 1.80429e+09
mavg 7 8 1 1.80429e+09
mavg 8 9 1 1.80429e+09
mavg 9 10 1 1.80429e+09
mavg 0 2 2 1.80429e+09
mavg 1 3 2 1.80429e+09

and so on ...
Could someone please point out what I might be doing
wrong ? Any hints, suggestions would be gratefully 
accepted.

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Strange STL vector behavior -- request help dakupoto@gmail.com - 2012-04-04 00:31 -0700
  Re: Strange STL vector behavior -- request help "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-04 22:38 +0200

csiph-web