+ 2
How can we make list<> in c++
list<> is present in c#.
4 Respuestas
+ 6
Be careful there! The C++ std::list<> actually resembles a linked list.
What you're searching for - the actual C++ equivalent of the C# list - is the std::vector<>.
It works exactly the same, just replace the word "list" with "vector" in Kinshuk's code.
+ 6
No problem. I didn't even know that std::list exists until I read your answer :D
+ 5
Steps:
1) Include <list>
2) Define a list object with the element
type inside the <>, for the template.
3) Do stuff with the list.
E.g. :
#include<iostream>
#include<list>
using namespace std;
int main()
{
list<int> ls; //List of integers.
for(int i = 0; i<5; i++)
ls.push_back(i+1);
// Push 5 integers into 'ls'.
for(int i:ls) cout<<i<<" ";
// Print 'ls'.
}
For more information, check out:
www.cplusplus.com/reference/list/list
+ 1
@Chris
Sorry, I thought C#'s list was a linked list as well, but it turns out to be a dynamic array.