Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I am trying to initialized 2D array of string in c++.
std::string A = new std::string [m+1][n+1]
But this is giving me error as array size in new-expression must be constant.
std::vector<std::vector<std::string>> A(...)
std::vector
std::array
new any_type[m][n]
You could do it the C-Style String way...
char ** array = new char*[10]; for (int i = 0; i < 10; ++i) { array[i] = new char[100]; }
Then you just delete it in the opposite order you created it when done.
Using the STL is probably a good choice if you need to be safe and modern.
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
std::vector<std::vector<std::string>> A(...).std::vectororstd::arrayinstead of thosenew any_type[m][n]