By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Using constants

P: n/a
Here is a real beginner type question:

I wish to use constants in place of numbers when dimensioning string
arrays. However I get an error when doing so. (Linux/KDevelop)

The following gives me the error "error: syntax error before `;' token"
and refers to the 'string s[MAX_ROW]; line.

#include <string>
#define MAX_ROW 256;

using namespace std;

string s[MAX_ROW];
int main(int argc, char *argv[])
{

return EXIT_SUCCESS;
}

However the following compiles cleanly:

#include <string>

using namespace std;

string s[256];
int main(int argc, char *argv[])
{

return EXIT_SUCCESS;
}

How can I use constants in dimensioning string arrays?

Thanks.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Suddn writes:
Here is a real beginner type question:

I wish to use constants in place of numbers when dimensioning string
arrays. However I get an error when doing so. (Linux/KDevelop)

The following gives me the error "error: syntax error before `;' token"
and refers to the 'string s[MAX_ROW]; line.

#include <string>
#define MAX_ROW 256;


Get rid of the ;. It is not a statement.

Jul 19 '05 #2

P: n/a

"Suddn" <Bo***@NoSpam.net> wrote in message
news:pa****************************@NoSpam.net...
Here is a real beginner type question:

I wish to use constants in place of numbers when dimensioning string
arrays. However I get an error when doing so. (Linux/KDevelop)

The following gives me the error "error: syntax error before `;' token"
and refers to the 'string s[MAX_ROW]; line.

#include <string>
#define MAX_ROW 256;

Get Rid of the ';' after the 256

When you use #define everything after the name is copied exactly into the
code at compile time

for example your MAX_ROW would end up doing this
string s[MAX_ROW]; will turn into string s[256;]; which obviously is

going to cause a compile error

Ali R.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.