List <string> in C ++
I'm cool with C #, but I'm new to C ++. I have searched but found many different solutions which mostly do not work, possibly because different versions of C ++ exist.
I am using turbo C ++ 4.5, I need something like C # List of strings
List<string> s = new List<string>(); s.Add("1");
I do know a bit about C ++ arrays, but I don't know the number of elements at the time of declaration and why I want to use a List like this so that I can declare once and add elements later.
someone told me that I should be doing this with pointers, but I don't know how. Is it possible? or are there any ways?
Please, if you have an answer, please explain why I really love learning, thank you.
source share
The C # equivalent List<T>
is std::vector<T>
. C ++ code that matches your C # code:
using namespace std; .... vector<string> s; s.push_back("1");
You shouldn't take advice to write such a class for yourself. If they fit, always use standard containers.
source share