F
F
fractum2016-10-20 17:40:37
C++ / C#
fractum, 2016-10-20 17:40:37

Dynamic string array using string, what's the problem?

#include <iostream>
#include <string>
using namespace std;

int i = 2;
string *a = new string[i];

int main()
{
  a[0] = "abc";
  a[1] = "del";
    i++;
    a[2] = "monday";
    cin.get(); cin.get();
  delete [] a;
  return 0;
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2016-10-20
@fractum

Honestly, the problem is your stupidity.
To get started, read the book. Everything is simple and easy there. Many questions will disappear by themselves.
PS By changing the variable i you will not change the size of the array s.

M
Mercury13, 2016-10-20
@Mercury13

i++;
    a[2] = "monday";

Out of bounds array. An array of length 2 has two elements: [0] and [1].

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question