stl字符串去除空格_在列表中推送字符并在C ++ STL中将它们打印为空格

stl字符串去除空格

In this example, we are declaring a character list and pushing the characters from 'A' to 'Z' using a for loop and push_back() function then printing the value of the vector separated by space.

在此示例中,我们声明了一个字符列表,并使用for循环和push_back()函数 将字符'A' 送到'Z' ,然后打印以空格分隔的向量的值

Code:

码:

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

int main()
{
    // list of character elements
    list<char> clist;

    // append characters from 'A' to 'Z'
    for (char i = 'A'; i <= 'Z'; ++i) {
        clist.push_back(i);
    }

    // printing all elements
    cout << "list (clist) elements: " << endl;
    for (char x : clist)
        cout << x << ' ';
    cout << endl;

    return 0;
}

Output

输出量

list (clist) elements:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


翻译自: https://www.includehelp.com/stl/push-characters-in-a-list-and-print-them-separated-by-space-in-cpp-stl.aspx

stl字符串去除空格

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值