Hello everybody! Please help me. I just learning now, how to programming in c++.
I have an error at the line 27. "expected a ')'. There is a red line under the "and" word. Please help on me.
In what header file is it defined? I'm been programming C for 25 years (though most of that was GNU C) and have never seen "and" used. Of course it could be #defined in a header but I don't think its a part of C++ I think "AND" is a part of BASIC. With that error it hasn't been #define(d)
But if you want to fix it:
#define and &&
#define or ||
#define not !
Operator Keyword for &&
The and operator is the text equivalent of &&. There are two ways to access the and operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option.
Sure, he can do that if he is using visual studio since it does not conform to the standard. If you use any other compiler you are going to get errors when you try to use that define.
#include <iostream>
#define and &&
int main()
{
std::cout << "Hello, world!" << std::endl;
if(true and true)
{
//nothing useful
}
return 0;
}
g++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
clang++ -stdlib=libc++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
main.cpp:3:9: error: "and" cannot be used as a macro name as it is an operator in C++
#define and &&
^
main.cpp:3:9: error: C++ operator 'and' (aka '&&') used as a macro name
#define and &&
Sure, he can do that if he is using visual studio since it does not conform to the standard. If you use any other compiler you are going to get errors when you try to use that define.
But he was getting an error so his compiler ( Visual Studio or not) doesn't support the standard completely. The fix is to simply #define it or include the header. I suspect a compile that does support the C++ 11 stadard completely wouldn't have the iso646 header since all it does is define the words for the logical and bit operands. I imagine Visual studio doesn't support that because it would break some internals, and the work around is the header.