Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: C++ problem need your input

  1. #11
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    WTF, ive never used Bloodshed before, use turbo, simple and best
    but shantz is right, getch(); is a function and one word.
    And shantz, getch() is included in iostream, except if you're using a 2-3 year old compiler.

    What command was that er0k ?
    I don't think commands change when compilers change.
    I mean i neva heard o that one before.

    One more thing, does Bloodshed dominate users in America ?
    duh, i mean the compiler.
    \"I have a 386 Pentium.\"

  2. #12
    er0k
    Guest
    Originally posted here by M/S Vin


    Erok, this one worked! Thanks! I appreciate it, and if you have some more to add please feel free to do so.
    np... anytime, im also new to C++ just have been through that b4

    invader >> that is the function you use with the standard library's on a simple output statement for it to stay "on screen" you can use the system('pause') as well its just not always portable. the cin.ignore() function is built in..

    edit >> sometimes its good practice to try something similar to this: ( if you are doing std work)

    #include <iostream>

    using namespace std;

  3. #13
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    built inside iostream ?
    \"I have a 386 Pentium.\"

  4. #14
    er0k
    Guest
    its a built in function yes, and iostream is a pre-processor directive that contains it yes to be frank. sorry id get you some more info from muuuucccch better programmers, ie a C++ book, but i need sleep.

  5. #15
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    C++ uses streams for input and output (this replaces C's printf() scanf() although still availible).

    Streams are in fact objects....
    You have four console streams automatically availible: cin, cout, cerr, clog

    cin reads from the console (standard input), cout writes to the console (standard output)...

    cin is an istream (actually it's derived from istream...)
    the class istream defines, amonst others, the operator ">>" (ie: operator>>() )
    which you use to read from a stream, in cin's case the stream is the standard input so it "reads from the keyboard".

    cout is an ostream
    the class ostream defines the operator "<<" (ie: operator<<() )
    which you use to write to a stream, in cout's case the standard output, so it "writes to the screen".

    as for cin.ignore():
    ignore() is a method of the class istream; by default (without params) it reads 1 character (or up to EOF) from the standard input ("keyboard") and discards it. Ie: it makes the application wait for the user to enter a character before continuing...

    Hope this clears things up...

    Ammo
    Credit travels up, blame travels down -- The Boss

  6. #16
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    The function getch() and the Alt+F5 combo work only with Turbo/Borland C++. So you have to use system("pause"); instead.
    Cheers,
    cgkanchi
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

  7. #17
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    as for cin.ignore():
    ignore() is a method of the class istream; by default (without params) it reads 1 character (or up to EOF) from the standard input ("keyboard") and discards it. Ie: it makes the application wait for the user to enter a character before continuing...
    urmm...doesnt getch() do the same ? Get a character from the user before continuing..
    Thanks anyway, ammo
    \"I have a 386 Pentium.\"

  8. #18
    #include<stdlib.h>
    #include<conio.h>
    #include<iostream.h>
    void main(){
    cout<<"Hello world";
    cout<<"\npress any key to quit....";
    while(getch()=='\0'){
    }
    _exit(0);
    }

  9. #19
    Originally posted here by invader
    WTF, ive never used Bloodshed before, use turbo, simple and best
    Im in enough confusion as it is.

    Originally posted here by cgkanchi
    The function getch() and the Alt+F5 combo work only with Turbo/Borland C++. So you have to use system(&quot;pause&quot; instead.
    Cheers,
    cgkanchi
    System pause didn't work either, and I get the message Implicit declaration of function int getch (...) But thanks.


    Originally posted here by black_death
    #include&lt;stdlib.h&gt;
    #include&lt;conio.h&gt;
    #include&lt;iostream.h&gt;
    void main(){
    cout&lt;&lt;&quot;Hello world&quot;;
    cout&lt;&lt;&quot;\npress any key to quit....&quot;;
    while(getch()=='\0'){
    }
    _exit(0);
    }
    I've tried the one you PM, it compiled successfully but It didn't run.

    Anymore help/info that you want to add, feel free to do so.

    Thank you for all the help .
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it.-Reaper Man

  10. #20
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    To use the system("pause") command you have to #include <cstdlib> at the beginning of the program. If that doesn't work, use #<stdlib.h>. And if that still doesn't work, get a real compiler at http://borland.com.
    Cheers,
    cgkanchi
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •