stl equal 浮点数_在C ++ STL中以浮点向量推送和打印元素

stl equal 浮点数

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.

在此示例中,我们声明一个浮点矢量,使用带有5个浮点值的push_back()函数推送元素 ,然后打印以空格分隔的值

Code:

码:

#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 posts

相关文章

翻译自: https://www.includehelp.com/stl/push-and-print-elements-in-a-float-vector-in-cpp-stl.aspx

stl equal 浮点数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值