#include"stdafx.h"
#include<cstdlib>
#include<iostream>
usingnamespace std;
int tmain(int argc, _TCHAR* argv[])
{
// Let's Declare Variables
int Num_Pegs; // Total number of pegs to a side
int Hold_Und; // Hold underscore location
 
 
// User Enters Number of Pegs
cout <<"Enter Number of Pegs:";
cin >>Num_Pegs;
 
 
// Array to create a board
char board[Num_Pegs * 2];
 
 
// Fill Array
for (int b = 0; b < Num_Pegs; b++)
 
For some reason, I keep getting an error from VC++ compiler saying "Expected a constant expression"? Also cannot allocate "size 0 array"?
When I run this program (Full Code) in DevC+, I have no problem!? But of course it has to be done in VC++ WIN32. Any help would be great!
Re: Visual C+ compiler trouble... 80 80

Come on your not all afraid of this novice problem are you?

Re: Visual C+ compiler trouble... 80 80

char board[Num_Pegs * 2]; is not valid c++. it is not even valid c, though g++ does allow it (unless you use the switch -std=c++98). standard c++ requires that the size of an array with an automatic or static storage duration should be a constant known at compile time. in this case, vc++ is right, devc++ is wrong. tip: *always* use the switch -std=c++98 (or std=c++0x, gcc 4.3) when using the gnu compiler to compile your C++ code.

Re: Visual C+ compiler trouble... 80 80
#include"stdafx.h"
#include<cstdlib>
#include<iostream>
usingnamespace std;
int tmain(int argc, _TCHAR* argv[])
{
// Let's Declare Variables
int Num_Pegs; // Total number of pegs to a side
int Hold_Und; // Hold underscore location
 
 
// User Enters Number of Pegs
cout <<"Enter Number of Pegs:";
cin >>Num_Pegs;
 
 
// Array to create a board
char board[Num_Pegs * 2];
 
 
// Fill Array
for (int b = 0; b < Num_Pegs; b++)

the 'board' variable is allocated on the stack, so it has to have fixed size. However, you want to have it of variable size.

Try using std::vector<char> instead.

Best,
John

Re: Visual C+ compiler trouble... 80 80

I'll try it thanX.....I just think it is funny that Dev(Bloodshed) finds it O.K., but VC2005 wont allow it?

Re: Visual C+ compiler trouble... 80 80

>I just think it is funny that Dev(Bloodshed) finds it O.K., but VC2005 wont allow it?
Your code is wrong, and one of the compilers you use happens to allow the wrong code while the other correctly bitches at you. That's typical behavior when you step out of the realm of standard C++.

Re: Visual C+ compiler trouble... 80 80
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
usingnamespace std;

Should be using namespace std; NOT usingnamespace std;

Re: Visual C+ compiler trouble... 80 80

Ah yes, thanx for all your "kind" help, I have once realized that I am still wallowing in the
bottom of the C..........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.