Home » C++ STL

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

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.