cancel
Showing results for 
Search instead for 
Did you mean: 

Print float on a vector

Gui_STM
Associate

Good afternoon,

I am testing my UART and using a vector to store float numbers as shown below:

 

raptor::std::vector<float> numbers;
  numbers.append(3.14f);
  numbers.append(2.21f);
  numbers.append(1.01f);
  numbers.append(8.15f);
  numbers.append(0.05f);
Here is how I am inserting float numbers into my vector. However, when I try to print them using:
    for(int i = 0; i < 5; i++)
      printf("%f ", numbers[i]);
Everything after the second number prints as 0. Below is an example of the output from my UART:
3.140000 2.210000 0.000000 -nan 0.000000
Can someone help me with this issue, please?
2 REPLIES 2
Pavel A.
Evangelist III

May be memory allocation does not work properly. It happens under the covers when c++ objects are constructed. Debug and look at the addresses of your c++ objects.

 

Ok, I will try to see where in the address is the bug.