Fam
Fam

Reputation: 23

Declaring a new long array c++

Am I declaring this correctly?

string regular = "TEST";
long[] cipher = new long[regular.length()];

Getting this compilation error: expected unqualified-id before '[' token

Upvotes: 1

Views: 2129

Answers (1)

a new expression returns a pointer, so your cipher must be one:

long *cipher = new long[regular.length()];

But using raw arrays is error prone. Consider substituting std::vector instead:

std::vector<long> cipher(regular.length());

Upvotes: 8

Related Questions