0

i've just started programming in visual studio 2012 Express and from the beginning I'm having problems with arrays.

The environment says that this code is invalid:

int a[10] = {5,1,8,9,7, 2,3,11, 20,15};

First of all i had to declare that this array has fixed size using fixed keyword, but after that the program still has been wanting to put ; after a[10]. Filling up this array one number by one would be waste of time. Is it possible to work around it? I can't find any solution in google so I decided to post my problem here.

asked Apr 17, 2014 at 9:13
6
  • Post the error? Also: which "fixed" keyword are you talking about? Commented Apr 17, 2014 at 9:16
  • Compiles for me (VS2012 Ultimate, Update 4). Commented Apr 17, 2014 at 9:18
  • 3
    There is no keyword fixed in C++. Commented Apr 17, 2014 at 9:18
  • No error found,Compiled successfully. Commented Apr 17, 2014 at 9:19
  • It should not give any error. It is strange the compiler wants ; after the declaration. Can you post a bit more of code, for example your main function? Anyway, don't use fixed. Commented Apr 17, 2014 at 9:19

2 Answers 2

3
  • There's no fixed keyword in C++, perhaps in C#
  • The code you posted is perfectly valid in VS2012 Ultimate (and probably also Express)

From the above I might conclude you mismatched project and are trying to compile a C++ code in a C# environment.

Another reason that makes me think the above is the following error you get in a C# project if you try to compile the snippet above:

error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.

which refers exactly to the fixed keyword you were trying to use.


Short story: you're trying to compile a C++ code in a C# project. Paste that code in a C++ project, not a C# one. Those are two different languages.

answered Apr 17, 2014 at 9:19
Sign up to request clarification or add additional context in comments.

1 Comment

Yup. That's the problem. I didn't noticed that by usings I don't know why.
-1

May be its too late to but you can use STL array for fix size arrays as

#include <array>
std::array<int, 5> ary { 1,2,3,4,5 }

This will be a fixed size array

As mentioned by Marco A. there is no "fixed" keyword in C++

answered Dec 21, 2016 at 4:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

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.

Ask question

Explore related questions

See similar questions with these tags.