D
D
Dauren S2016-10-15 21:02:31
C++ / C#
Dauren S, 2016-10-15 21:02:31

If I don't know how many elements will be in the c++ array?

string c[3];
And if I don’t know how many elements will be in the array? how can I declare such an array where the elements can be 1000 or 100,000.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MiiNiPaa, 2016-10-15
@dauren101

std::vector<std::string> c;

V
Vitaly Stolyarov, 2016-10-15
@Ni55aN

Dynamic arrays
Select the minimum number, if more is needed, then allocate space for a larger one and copy the existing ones there. It all depends on how much and how often you have to write there.
But in order not to take a steam bath, you can use lists

C
CodeInside, 2016-10-19
@CodeInside

#include <iostream>
using namespace std;

void main()
{
    int count;
    cout << "Input count of elements: ";
    cin >> count;
    
    int* arr = new int[count]; // Вот Ваш массив с указанным пользователем количеством элементов (count)
    delete[] arr;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question