Skip to main content
Graduate
November 28, 2024
Question

Print float on a vector

  • November 28, 2024
  • 1 reply
  • 571 views

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?
    This topic has been closed for replies.

    1 reply

    Super User
    November 28, 2024

    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.

     

    Gui_STMAuthor
    Graduate
    November 28, 2024

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