I'm cool with C# but am new to C++. I searched but found lots of different solutions which mostly do not work maybe because there are different versions of C++.
I'm using turbo C++ 4.5, I want something like C#'s List of strings
List<string> s = new List<string>();
s.Add("1");
I know a bit about C++ arrays, but I do not know the count of items at declaration time and that's why I want List-like solution so that I can declare once and add items later.
someone told me I should do it using pointers but I don't know how. Is it possible? or there any ways?
Please if you have an answer explain it cause I really like to learn, thanks.
The equivalent to C# List<T>
is std::vector<T>
. The C++ code that corresponds to your C# code is this:
using namespace std;
....
vector<string> s;
s.push_back("1");
You should not take the advice to write such a class for yourself. Where they are appropriate, always use the standard containers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With