1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error here

Discussion in 'C++' started by Carlos, Dec 7, 2008.

  1. Carlos

    Carlos New Member

    Joined:
    Dec 5, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    none
    Code:
    #pragma once
    #include <iostream>
    using namespace std;
    int main()
    {
        int num,cout=0;
        cout <<"Enter the number:";    //here is the error
        cin>>num;
    
    bool done=true;
        while(done)
        {
            if (num>=10)
            {
                num=num/10;
                cout++;
            }
            else 
            {
                cout++;
                done=false;
            }
        }
    printf ("%d",cout); // its working fine
    system("pause");
        return 0;
    }
    Error: Can anyone tell me why this error is occuring, it's point at the "cout" statement.
    as much as cout i m using errors are increasing.
    Error 1 error C2297: '<<' : illegal, right operand has type 'const char [18]'
    Warning 2 warning C4552: '<<' : operator has no effect; expected operator with side-effect
     
    Last edited by a moderator: Dec 7, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    You've redefined cout as an int and set it to zero on the previous line.

    The error is correct because you can't shift left an integer by a char array number of bits - this is meaningless. You can only shift an integer left by another integer.
     

Share This Page