Simple question

Posts 1–8 of 8 · Page 1 of 1
Simple question
Its possible to declare something like...

#define n1to9 (i == (1 to 9))

or something?
Like if i is 1 to 9, but in a declaration..
I dont want answers like tell me to do:
if(i <= 9 && i > 0) or something...


i just wanna know if is possible and how to declare a variable like that..
1 to 9 or something....
You mean an array?

int i [] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Changed it to C++ only had to move 1 thing xD
#include <vector>

vector oneToNine;
for(int i = 1; i <= 9; i++)
oneToNine.push_back(i);

use vectors
Quote Originally Posted by Auxilium View Post
#include <vector>

vector oneToNine;
for(int i = 1; i <= 9; i++)
oneToNine.push_back(i);

use vectors
Oh thanks! I learned something even though i didn't ask the question xD Thanks!
You can define almost anything you want, but you need to remember that the compiler won't give you a numerical result from #define.

#define is a preprocessor(Hence the '#'). The compiler will go through anything with a '#' before compiling the program, and with #define (in reference to your original post) it will replace every 'n1to9' it finds with '(i == (1 to 9))'. Then compile the program.

As long as whatever you are using it with can take an expression instead of just a variable you shouldn't have a problem.

But i don't know if it will work with any spaces. You will have to figure that out yourself.
@Lyoto Machida




Quote Originally Posted by Auxilium View Post
#include <vector>

vector oneToNine;
for(int i = 1; i <= 9; i++)
oneToNine.push_back(i);

use vectors
I always end up mindfucking myself over vectors.
Quote Originally Posted by Lyoto Machida View Post
Its possible to declare something like...

#define n1to9 (i == (1 to 9))

or something?
Like if i is 1 to 9, but in a declaration..
I dont want answers like tell me to do:
if(i <= 9 && i > 0) or something...


i just wanna know if is possible and how to declare a variable like that..
1 to 9 or something....
Well, I guess you could...

Since C++ isn't VB, you can't use VB syntax <<

Replace

Code:
#define n1to9  (i == (1 to 9))
with
Code:
#define n1to9  (i >= 1 && i <= 9)


Quote Originally Posted by Disturbed View Post
You can define almost anything you want, but you need to remember that the compiler won't give you a numerical result from #define.

#define is a preprocessor(Hence the '#'). The compiler will go through anything with a '#' before compiling the program, and with #define (in reference to your original post) it will replace every 'n1to9' it finds with '(i == (1 to 9))'. Then compile the program.

As long as whatever you are using it with can take an expression instead of just a variable you shouldn't have a problem.

But i don't know if it will work with any spaces. You will have to figure that out yourself.
@Lyoto Machida






I always end up mindfucking myself over vectors. :confused:
Vectors aren't thread safe :(
Nope none of that....
If i make a array im gonna need to make like shit[9] = {0,1,2,3,4,5,6,7,9,+,9,859,89,8,96............}

There is not a way like..
shit[]= {1-9}
?
Well ty, I see what i want is not possible...Thank you all anyway
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us