Using constants

S

Suddn

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.
 
A

Ali R.

Suddn said:
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.
 
O

osmium

Suddn said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top