To create a list of strings in C++ using std::list, you can directly initialize a list with string elements.
In this example,
header for std::list functionality.string_list
with string elements.{}
using list initialization.#include <iostream>
#include <list>
#include <string>
int main() {
std::list<std::string> string_list = {"Apple", "Banana", "Cherry"};
for (const auto &str : string_list) {
std::cout << str << std::endl;
}
return 0;
}
Apple Banana Cherry
In this tutorial, we learned How to create a List of Strings in C++ language with well detailed examples.