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


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

Re: Strange STL vector behavior -- request help

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Strange STL vector behavior -- request help
Date 2012-04-04 22:38 +0200
Organization A noiseless patient Spider
Message-ID <jlibgu$mra$1@dont-email.me> (permalink)
References <3258921.1909.1333524687267.JavaMail.geo-discussion-forums@pbcwe9>

Show all headers | View raw


On 04.04.2012 09:31, dakupoto@gmail.com wrote:
> 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();

Don't clear the vector.


>   /*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'

Use the vector size rather than MAXELEM.

Use '.at( i )'  instead of '[i]' (because of current problems).

Generally, do not user ALL UPPERCASE except for macro names.

For C++ constants, use `const` instead of macro definitions.

[snip]


Cheers & hth.,

- Alf

Back to comp.lang.c++ | Previous | Next — Previous 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