How to push characters and print a list in C++

1 Answer

0 votes
#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

int main()
{
	list<char> lst;

	for (int i = 0; i < 5; i++)
		lst.push_back('a' + i);

	cout << lst.size() << endl;

	list<char>::iterator p;

	while (!lst.empty()) {
		p = lst.begin();
		cout << *p;
		lst.pop_front();
	}

	cout << endl;

	return 0;
}



/*
run:

5
abcde

*/

 



answered Apr 20, 2018 by avibootz

Related questions

1 answer 300 views
1 answer 143 views
1 answer 187 views
1 answer 198 views
1 answer 148 views
148 views asked Jun 6, 2024 by avibootz
1 answer 184 views
...