c++ confusion

This is a discussion on c++ confusion within the C++ Programming forums, part of the General Programming Boards category; ok i just started learning c++ (with q basic background) and i was working on a program when i go ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    34

    c++ confusion

    ok i just started learning c++ (with q basic background) and i was working on a program when i go to compile it there is an error and it stops here is the code can someone point out my problem? i am using microsoft visual c++

    #include <iostream.h>

    int main ()

    {
    int number,
    int name,

    cout<<"Hey hey enter a number please!";
    cin>>number;
    cout<<"Is this your number?">>number;

    return 0;
    }

    (yeah its from the tutorial)

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Try the following. First remember that semicolons end C++ statements. Also, no standard header has .h at the end.

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    
    {
    int number;
    int name;
    
    cout<<"Hey hey enter a number please!";
    cin>>number;
    cout<<"Is this your number?">>number;
    
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    34
    i tried your version and i got this error
    --------------------Configuration: lesson - Win32 Debug--------------------
    Compiling...
    lesson1 prog.cpp
    c:\program files\microsoft visual studio\myprojects\lesson\lesson1 prog.cpp(16) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.

    lesson.exe - 1 error(s), 0 warning(s)
    Last edited by Goku-ssj; 09-10-2002 at 06:15 PM.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    try just add the semicolons SilentStrike mentioned to your code and leave out the namespace line, and use the .h extension on the header file. If that works then your compiler isn't namespace compliant and it doesn't use the latest "standard" header file system. It's still an okay compiler, but it just isn't the latest and greatest version.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    34
    nope still not working

    --------------------Configuration: lesson - Win32 Debug--------------------
    Compiling...
    lesson1 prog.cpp
    c:\program files\microsoft visual studio\myprojects\lesson\lesson1 prog.cpp(15) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    Error executing cl.exe.

    lesson1 prog.obj - 1 error(s), 0 warning(s)


    same error =(

  6. #6
    Xei
    Xei is offline
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    This works:

    Code:
    #include <iostream.h>
    //using namespace std; //Why this?
    
    int main ()
    {
    int number;
    int name;
    cout<<"Hey hey enter a number please!";
    cin>>number;
    cout<<"\nIs this your number? "<<number<<"\n";
    return 0;
    }

  7. #7
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You probably copied something wrong (I am guessing on the first line).
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    34
    lets go back a step what type of file should i make (ive been using c/c++ source) because i got the same error i dont think its a code problem anymroe i think its something with my install

  9. #9
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    If you are using MSVC6, create a C++ Console Application, make it empty then add a new file to the project, and then copy and paste that code into it.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    34
    thx all for your help this code worked in the file and project just listed =)

    this is the code

    #include <iostream.h>
    //using namespace std; //Why this?

    int main ()
    {
    int number;
    int name;
    cout<<"Hey hey enter a number please!";
    cin>>number;
    cout<<"\nIs this your number? "<<number<<"\n";
    return 0;
    }

    i was using win32 application and not console application i think that might have bene it

  11. #11
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Actually Silent Strike made a typo here on this line:

    Code:
    cout<<"Is this your number?">>number;
    
    return 0;
    }
    Otherwise his code should have worked fine.

    Also, the correct way to use the header

    Goku-ssj is

    Code:
    #include <iostream>
    using namespace std;
    Don't comment the line out. In C++, there is a concept called a namespace and here we are calling the standard namespace because that is where cin and cout our found.

    Mr. C.

  12. #12
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Yeah, my bad.. I didn't check the code well enough .
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  13. #13
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    again, only use the iostream version and namespace line if your compiler is compliant with those concepts. New compilers should be, older version probably won't be. Standards take time to permeate throughout the entire programming universe. Many of us still use older compilers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terrible confusion with time variables
    By LowlyIntern in forum C++ Programming
    Replies: 12
    Last Post: 08-01-2008, 08:23 AM
  2. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 02:46 AM
  3. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 09:21 AM
  4. Server-net newbie confusion
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2005, 03:08 AM
  5. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 03:45 PM

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