What does this error mean?

This is a discussion on What does this error mean? within the C++ Programming forums, part of the General Programming Boards category; I'm using Bloodshed Dev-C++ and I just started learning C++, so please dont get mad at me if the answer ...

  1. #1

    What does this error mean?


    I just wrote a small program, and it gives me this error:

    Line 16 c:\c__sou~1\q.cpp
    initialization to `char' from `const char *' lacks a cast

    could anyone tell me what this means?


  2. #2
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Yes I could, but I may be wrong without seeing the code. Please post the offending code.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  3. #3
    Here's the source:

    #include <iostream.h>
    #include <stdlib.h>

    int main()

    char ans1;
    char ans2;
    char ans3;
    char ans4 = "a";
    char ans5 = "c";
    char ans6 = "b";

    cout<<"Welcome to ";
    cout<<"Questions and Answers v1.0beta";
    cout<<"\nPlease type the letter of your answer in lower-case and press enter\n\n"
    <<"1: When the Nintendo was released in Japan, what was its original name?\n"
    <<"A.Famicom\nB.Magic Gray Game Box\nC.Tanacom\nYour Answer: ";
    cout<<"\n\n2: Sega made a hand-held video game system which looks similar to the Gameboy Advance. What was it called?\n"
    <<"A.Gameboy Pocket\nB.NeoGeo Pocket\nC.Game Gear\nYour Answer: ";
    cout<<"\n\n3: True or false, Sega created an add-on to the Sega Genesis called the 32X?\n"
    <<"A.No\nB.Yes\nYour Answer: ";
    cout<<"\n\n\nPlease wait while your score is calculated..."

    if(ans1 == ans4) {
    cout<<"Question 1: Correct.\n";
    else {
    cout<<"Question 1: Incorrect. Answer: Famicom.\n";
    if(ans2 == ans5) {
    cout<<"Question 2: Correct.\n";
    else {
    cout<<"Question 2: Incorrect. Answer: Game Gear.\n";
    if(ans3 == ans6) {
    cout<<"Question 3: Correct.\n";
    else {
    cout<<"Question 3: Incorrect. Answer: Yes.\n";

    cout<<"\n\n\nThank you for playing!\n\n";

    return 0;

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >char ans4 = "a";
    No, a single char cannot hold two characters. The double quotes say that this is a string, which is actually represented as

    "a" == 'a', '\0'

    Which results in an error because this is an invalid assignment.

    My best code is written with the delete key.

  5. #5


    thanks for telling me

  6. #6
    Registered User
    Join Date
    Apr 2002
    In case you didn't figure it out just use single quotes.

    char ans4 = 'a';

Popular pages Recent additions subscribe to a feed
