Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 25, 2015 16:52
Show Gist options
  • Save krysseltillada/5078ea451418df3fbf4f to your computer and use it in GitHub Desktop.
Save krysseltillada/5078ea451418df3fbf4f to your computer and use it in GitHub Desktop.
std::forward_list
#include <iostream>
#include <string>
#include <forward_list>
void add_str (std::forward_list <std::string> flst, std::string str1 = "", std::string str2 = "") {
if (!str1.empty()) {
flst.insert_after (flst.before_begin(), str2);
flst.insert_after (flst.before_begin(), str1);
} else {
flst.insert_after (flst.before_begin(), str2);
}
for (auto i : flst)
std::cout << i << " ";
}
int main ()
{
std::forward_list <std::string> f1;
add_str (f1, "world");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment