Storing strings in a list - C++ STL

C++ examples for STL:list

Description

Storing strings in a list

Demo Code

#include <string>
#include <list>
#include <algorithm>
#include <iostream>

using namespace std;

void write(const string& s) {
   cout << s << '\n';
}

int main() {//from www.j  a  v a 2 s.  com
   list<string> lst;

   string s = "a";
   lst.push_front(s);

   s = "b";
   lst.push_back(s);

   s = "c";
   lst.push_back(s);

   for_each(lst.begin(), lst.end(), write);
}

Result


Related Tutorials