humm doesnt want to complie

This is a discussion on humm doesnt want to complie within the C++ Programming forums, part of the General Programming Boards category; Hi ppl I am very very new to c++ and I have just bought Sams Teach Yourself c++ book and ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    humm doesnt want to complie

    Hi ppl I am very very new to c++ and I have just bought Sams Teach Yourself c++ book and I got my first Hello World program tp run but the next one it gives me wont execute this is what I wrote

    #include <iostream>
    int main()
    {
    int x = 5;
    int y = 7;
    std::cout << "\n";
    std::cout << x + y << " " << x * y;
    std::cout << "\n";
    cin.get()
    return 0;
    }

    Thanx In Advance

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    cin.get()
    // should be
    std::cin.get()
    Nice to see beginners using the new style headers .
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953

    Re: humm doesnt want to complie

    Originally posted by a.lost.soul
    Hi ppl I am very very new to c++ and I have just bought Sams Teach Yourself c++ book and I got my first Hello World program tp run but the next one it gives me wont execute this is what I wrote

    #include <iostream>
    int main()
    {
    int x = 5;
    int y = 7;
    std::cout << "\n";
    std::cout << x + y << " " << x * y;
    std::cout << "\n";
    cin.get()
    return 0;
    }

    Thanx In Advance
    Maybe you should learn doing this:
    Code:
    #include <iostream>
    using namespace std; //adding this line
    int main()
    {
     int x = 5;
     int y = 7;
     cout << "\n";
     cout << x + y << " " << x * y;
     cout << "\n";
     cin.get()
     return 0;
    }
    It's easier this way...
    none...

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    why not do this.

    [code]

    #include <iostream.h>/* add the .h then you dont need name spaces.*/

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Because the .h headers are old C++ and are outdated. The standard C++ states that it is iostream (w/out the .h).

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    your just missing a semicolon on the std::cin.get();
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    You also need a semicolon to terminate cin.get()

    Code:
    #include <iostream>
    
    int main()
    {
    	std::cout << "\n12 35\n";
     	std::cin.get();
    
     	return 0;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Config MVS to complie C
    By ph071 in forum C Programming
    Replies: 14
    Last Post: 12-04-2008, 12:30 PM
  2. Complie / cmd
    By DDAZZA in forum Tech Board
    Replies: 12
    Last Post: 06-11-2007, 10:42 PM
  3. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM

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