I am new to programming and this is my second assignment. It is supposed to accept input from user until they enter the | to exit the program. What have I done wrong?
int main()
int i = 0;
char a = 0;
while ( a != "|" ){ //has also told me this is an
// invalid operator
int numeric;
cout << "Give character: ";
cin >> a ;
cout << "Its ascii value is: " << (int) a << endl;
++i;
}
}
Here is the error:
2 IntelliSense: operand types are incompatible ("char" and "const char *")
's instead of"s"s results in a string literal, which is of typeconst char *. This is a pointer to an array of characters. You can't compare a single char to an array of characters. Use|.const char *" - a string literal is actually an array ofconst char, not aconst char*; the confusion's not uncommon given the standard conversion toconst char*kicks in quite readily. The difference is significant: e.g. forsizeofand when passing it totemplate <size_t N> void f(char (&s)[N]);.