Thread: I NEED #define HELP!!!!

  1. #16
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    Ok. It works perfectly

    #include <iostream>
    using std::cout;
    const int ONE = 1;
    const int TWO = 2;

    int main()
    {

    int sum = ONE + TWO;
    cout<<"\n\n "<<sum;
    cout<<"\n***************************************** *********************";
    cout<<"\n ";
    return 0;
    }

  2. #17
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    I ran this , but I think here is a lost header
    #include <iostream>

    #define ONE 1
    #define TWO 2
    #define THREE 3

    int main()
    {
    int sum = ONE + TWO + THREE;
    cout << ONE << endl;
    cout << TWO << endl;
    cout << THREE << endl;
    cout << "Sum: " << sum << endl;
    }

    make me this errors
    :\numbers.cpp(14) : error C2065: 'cout' : undeclared identifier
    C:\numbers.cpp(14) : error C2065: 'endl' : undeclared identifier
    C:\numbers.cpp(14) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
    C:\numbers.cpp(15) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
    C:\numbers.cpp(16) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
    C:\numbers.cpp(17) : error C2297: '<<' : illegal, right operand has type 'char [6]'
    C:\numbers.cpp(18) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Error executing cl.exe.

    numbers.obj - 3 error(s), 4 warning(s)

    so I put this using std::cout;
    C:\numbers.cpp(16) : error C2065: 'endl' : undeclared identifier
    C:\numbers.cpp(20) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Error executing cl.exe.

    numbers.exe - 1 error(s), 1 warning(s)
    so i put return 0;
    C:\numbers.cpp(16) : error C2065: 'endl' : undeclared identifier
    Error executing cl.exe.
    so finally my question is to endl , I dont know the header , would u please explain me???
    thx in adv.

  3. #18
    Registered User
    Join Date
    Jul 2004
    Posts
    101
    If you use the new headers then you must also remember that every standard name is embedded within the std namespace.
    Code:
    #include <iostream>
    
    using namespace std; // Add this for the easiest fix
    
    #define ONE 1
    #define TWO 2
    #define THREE 3
    
    int main()
    {
      int sum = ONE + TWO + THREE;
      cout << ONE << endl;
      cout << TWO << endl;
      cout << THREE << endl;
      cout << "Sum: " << sum << endl;
    }

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    abyssphobia
    Please use the code tags - read the announcements etc
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 10:20 PM
  2. Why?!?
    By p3rry in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 12:52 PM
  3. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  5. float toolbar!
    By c-- in forum Windows Programming
    Replies: 5
    Last Post: 02-04-2003, 09:44 AM