×

C++ STL Tutorial

C++ STL Algorithm

C++ STL Arrays

C++ STL String

C++ STL List

C++ STL Stack

C++ STL Set

C++ STL Queue

C++ STL Vector

C++ STL Map

C++ STL Multimap

C++ STL MISC.

Push and print elements in a float vector in C++ STL

C++ STL Vector: Here, we are implementing a program in which we are declaring a float vector, pushing the elements and printing the elements.
Submitted by IncludeHelp, on June 18, 2019

Push and print elements in a float vector

In this example, we are declaring a float vector and pushing the elements using push_back() function with the 5 float values and then printing the value separated by space.

Example

#include <iostream>
#include <vector>  //for vector
using namespace std;

int main() {
  // vector  for float elements
  vector<float> v1;

  // adding 5 elements
  v1.push_back(10.20f);
  v1.push_back(89.30f);
  v1.push_back(12.11f);
  v1.push_back(33.33f);
  v1.push_back(22.19f);

  // print all elements
  cout << "vector elements are: ";
  for (int i = 0; i < v1.size(); ++i) {
    cout << v1[i] << ' ';
  }
  cout << endl;

  return 0;
}

Output

vector elements are: 10.2 89.3 12.11 33.33 22.19

Related Tutorials

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.