Illegal operands, why the errors?

This is a discussion on Illegal operands, why the errors? within the C++ Programming forums, part of the General Programming Boards category; I am a noob at this quite honestly. I am trying to run a program that I found on the ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    14

    Illegal operands, why the errors?

    I am a noob at this quite honestly. I am trying to run a program that I found on the board and I am getting these errors. I am using Microsoft Visual C++.

    What is the reason for these errors? and how would they be resolved?

    Code:
    h:\c\calendar.c(229) : error C2065: 'cout' : undeclared identifier
    h:\c\calendar.c(229) : error C2297: '<<' : illegal, right operand has type 'char [9]'
    h:\c\calendar.c(229) : error C2065: 'endl' : undeclared identifier
    h:\c\calendar.c(232) : error C2297: '<<' : illegal, right operand has type 'char [17]'
    h:\c\calendar.c(233) : error C2065: 'cin' : undeclared identifier
    h:\c\calendar.c(233) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
    h:\c\calendar.c(236) : warning C4013: 'clrscr' undefined; assuming extern returning int
    h:\c\calendar.c(247) : error C2297: '<<' : illegal, right operand has type 'char [9]'
    h:\c\calendar.c(251) : error C2297: '<<' : illegal, right operand has type 'char [10]'
    h:\c\calendar.c(255) : error C2297: '<<' : illegal, right operand has type 'char [7]'
    h:\c\calendar.c(259) : error C2297: '<<' : illegal, right operand has type 'char [7]'
    h:\c\calendar.c(263) : error C2297: '<<' : illegal, right operand has type 'char [5]'
    h:\c\calendar.c(267) : error C2297: '<<' : illegal, right operand has type 'char [6]'
    h:\c\calendar.c(271) : error C2297: '<<' : illegal, right operand has type 'char [6]'
    h:\c\calendar.c(275) : error C2297: '<<' : illegal, right operand has type 'char [8]'
    h:\c\calendar.c(279) : error C2297: '<<' : illegal, right operand has type 'char [11]'
    h:\c\calendar.c(283) : error C2297: '<<' : illegal, right operand has type 'char [9]'
    h:\c\calendar.c(287) : error C2297: '<<' : illegal, right operand has type 'char [10]'
    h:\c\calendar.c(291) : error C2297: '<<' : illegal, right operand has type 'char [10]'
    h:\c\calendar.c(298) : error C2297: '<<' : illegal, right operand has type 'char [38]'
    h:\c\calendar.c(299) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
    h:\c\calendar.c(305) : error C2297: '<<' : illegal, right operand has type 'char [67]'
    h:\c\calendar.c(308) : error C2297: '<<' : illegal, right operand has type 'char [36]'
    h:\c\calendar.c(309) : error C2297: '<<' : illegal, right operand has type 'char [27]'

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Sounds like you didn't include the appropriate headers for cout.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Originally posted by Govtcheez
    Sounds like you didn't include the appropriate headers for cout.
    What would the solution be? I just wanted to view the program...

    I suppose I need the header files right? Where do I get those?
    Last edited by Kons; 08-26-2003 at 07:14 AM.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    #include <iostream>
    then the namespace bit:
    using namespace std;
    or
    using std::cout;
    or
    std::cout <<"Something";

    Thread moved to the C++ forum.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > I suppose I need the header files right? Where do I get those?

    They came with your compiler. At least, they damn well should have.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    I added iostream. The file needed to be renamed to .cpp

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You should never include cpp files, only h (header) files.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    14
    Originally posted by Magos
    You should never include cpp files, only h (header) files.
    No, I meant I renamed the prog to calendar.cpp and ran it and it worked fine.

    It was named calendar.c

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I think he means his source file. I'm guessing he had it as sdhfksd.c rather than sdhfksd.cpp, thus it used the C compiler not the C++.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Ops, my mistake
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  3. Struct of Rects can't compile
    By vrek in forum Windows Programming
    Replies: 10
    Last Post: 04-20-2007, 10:21 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21