×

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 characters in a list and print them separated by space in C++ STL

C++ STL list: Here, we are implementing a program in which we are declaring a character list, pushing the characters and printing them separated by space.
Submitted by IncludeHelp, on June 18, 2019

Push characters in a list and print them separated by space

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.

C++ program to push characters in a list and print them separated by space

#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

Comments and Discussions!

Load comments ↻





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