I NEED #define HELP!!!!

This is a discussion on I NEED #define HELP!!!! within the C++ Programming forums, part of the General Programming Boards category; Ok. It works perfectly #include <iostream> using std::cout; const int ONE = 1; const int TWO = 2; int main() ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
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, 11:52 AM
  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, 08:22 AM
  5. float toolbar!
    By c-- in forum Windows Programming
    Replies: 5
    Last Post: 02-04-2003, 08:44 AM

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