官术网_书友最值得收藏!

Code walkthrough

The following code declares and initializes the forward_list container with some unique values and some duplicate values:

forward_list<int> l = { 10, 10, 20, 30, 45, 45, 50 };

As the forward_list container doesn't support the size() function, we used the distance() function to find the size of the list:

cout << "\nSize of list with duplicates is " << distance( l.begin(), l.end() ) << endl;

The following forward_list<int>::unique() function removes the duplicate integers and retains only the unique values:

l.unique();
主站蜘蛛池模板: 台中市| 西林县| 基隆市| 封开县| 仁化县| 洛浦县| 绵阳市| 成安县| 油尖旺区| 疏勒县| 东兴市| 乐至县| 南陵县| 奎屯市| 琼结县| 陆川县| 陵水| 斗六市| 会理县| 朝阳区| 承德市| 苍山县| 嘉善县| 清水县| 石柱| 吉木萨尔县| 夏河县| 鲁山县| 二连浩特市| 桃园市| 丹阳市| 东山县| 新乡市| 徐汇区| 武山县| 论坛| 宁夏| 昌吉市| 姚安县| 固安县| 琼中|