I am building a very simple question. I want to create a dynamically array of strings in C ++.
How can i do this?
This is my attempt:
#include <iostream> #include <string> int main(){ unsigned int wordsCollection = 6; unsigned int length = 6; std::string *collection = new std::string[wordsCollection]; for(unsigned int i = 0; i < wordsCollection; ++i){ std::cin>>wordsCollection[i]; } return 0; }
But this gives the following error:
error C2109: subscript requires array or pointer type
What mistake?
And also, if I get the input number from the user, from std::cin can I create an array of this size statically?
source share