C++ code to demonstrate forward list part - 5

Suman Barik
0

#include <forward_list> // for using forward list

#include <iostream>

using namespace std;


int main()

{

// creating forward list

forward_list<int> flist{ 1, 2, 3, 4, 5 };


//Printing forward list

cout<<"Forward list: ";

for(auto i: flist){

cout<<i<<" ";

}

cout<<endl;




flist.clear();

// Forward List becomes empty




// Printing the Forward list

cout<<"Forward list after using clear function: ";

for (auto it = flist.begin(); it != flist.end(); ++it)

cout << ' ' << *it;

cout<<endl;



return 0;

}


Tags

Post a Comment

0Comments
Post a Comment (0)