wait for keyboard entry ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pelo GANDO

    wait for keyboard entry ?

    Hi everybody,

    It's me again...Pelo, for an other beginner question...

    What the code should be in C++ to wait for a keyboard entry in order to
    execute the sequal of my program...




  • Pelo GANDO

    #2
    getch() function

    I found by myself...

    #include <conio.h>
    cout << "Press any key to terminate this program. " ; getch();

    The getch() function call causes the program to wait for a single keystroke.





    "Pelo GANDO" <o0593m@hotmail .com> a écrit dans le message de news:
    c26rlv$i9v$1@ne ws-reader3.wanadoo .fr...[color=blue]
    > Hi everybody,
    >
    > It's me again...Pelo, for an other beginner question...
    >
    > What the code should be in C++ to wait for a keyboard entry in order to
    > execute the sequal of my program...
    >
    >
    >
    >[/color]


    Comment

    • Mike Wahler

      #3
      Re: [OT, welcome msg] getch() function

      "Pelo GANDO" <o0593m@hotmail .com> wrote in message
      news:c26t39$8t0 $1@news-reader5.wanadoo .fr...[color=blue]
      > I found by myself...
      >
      > #include <conio.h>
      > cout << "Press any key to terminate this program. " ; getch();
      >
      > The getch() function call causes the program to wait for a single[/color]
      keystroke.

      But alas it's not part of the C++ language. It's an
      'extension' provided by your implementation, not topical
      here. Here we discuss the ISO standard C++ langauge, which
      has no means to do what you're asking.

      See:


      -Mike



      Comment

      • Pelo GANDO

        #4
        Re: [OT, welcome msg] getch() function

        thank you !


        "Mike Wahler" <mkwahler@mkwah ler.net> a écrit dans le message de news:
        5XC1c.20812$aT1 .4581@newsread1 .news.pas.earth link.net...[color=blue]
        > "Pelo GANDO" <o0593m@hotmail .com> wrote in message
        > news:c26t39$8t0 $1@news-reader5.wanadoo .fr...[color=green]
        > > I found by myself...
        > >
        > > #include <conio.h>
        > > cout << "Press any key to terminate this program. " ; getch();
        > >
        > > The getch() function call causes the program to wait for a single[/color]
        > keystroke.
        >
        > But alas it's not part of the C++ language. It's an
        > 'extension' provided by your implementation, not topical
        > here. Here we discuss the ISO standard C++ langauge, which
        > has no means to do what you're asking.
        >
        > See:
        > http://www.slack.net/~shiva/welcome.txt
        >
        > -Mike
        >
        >
        >[/color]


        Comment

        • Pelo GANDO

          #5
          Re: [OT, welcome msg] getch() function

          Sir,
          How would you do in ISO standard C++...
          I would like knwo from you...

          Thank you

          "Mike Wahler" <mkwahler@mkwah ler.net> a écrit dans le message de news:
          5XC1c.20812$aT1 .4581@newsread1 .news.pas.earth link.net...[color=blue]
          > "Pelo GANDO" <o0593m@hotmail .com> wrote in message
          > news:c26t39$8t0 $1@news-reader5.wanadoo .fr...[color=green]
          > > I found by myself...
          > >
          > > #include <conio.h>
          > > cout << "Press any key to terminate this program. " ; getch();
          > >
          > > The getch() function call causes the program to wait for a single[/color]
          > keystroke.
          >
          > But alas it's not part of the C++ language. It's an
          > 'extension' provided by your implementation, not topical
          > here. Here we discuss the ISO standard C++ langauge, which
          > has no means to do what you're asking.
          >
          > See:
          > http://www.slack.net/~shiva/welcome.txt
          >
          > -Mike
          >
          >
          >[/color]


          Comment

          • amateur

            #6
            Re: wait for keyboard entry ?


            "Pelo GANDO" <o0593m@hotmail .com> wrote in message
            news:c26rlv$i9v $1@news-reader3.wanadoo .fr...[color=blue]
            > Hi everybody,
            >
            > It's me again...Pelo, for an other beginner question...
            >
            > What the code should be in C++ to wait for a keyboard entry in order to
            > execute the sequal of my program...
            >[/color]

            c++ doesn't have such a concept.

            If you work under character environments such as unix or old dos you'll
            usually call a single function to achieve that. Non standard headers like
            <conio.h> for dos may provide what you're looking for. Others will point you
            to correct newsgroups.

            If you work under some GUI like Windows or the X, than your whole program
            concept changes. You wait for specific messages/callbacks from your
            OS/GUI/Framework manager or whatever. And that's a complex topic which is
            not discussed here.


            Comment

            • Mike Wahler

              #7
              Re: [OT, welcome msg] getch() function

              "Pelo GANDO" <o0593m@hotmail .com> wrote in message
              news:c26ucq$qcb $1@news-reader2.wanadoo .fr...[color=blue]
              > Sir,
              > How would you do[/color]

              [nonblocking input]
              [color=blue]
              >in ISO standard C++...
              > I would like knwo from you...[/color]

              Like I said, it cannot be done with standard C++.
              You'll need to use an extension, such as the
              one you mentioned. However you should note
              that this will only work with that particular
              compiler, others will have their own way, if
              they have any at all. When you encounter this
              situation, I advise you to isolate and clearly
              identify such uses, so porting will be easier
              when the time comes.

              -Mike


              Comment

              • Jacob Jensen

                #8
                Re: wait for keyboard entry ?

                > What the code should be in C++ to wait for a keyboard entry in order to[color=blue]
                > execute the sequal of my program...
                >[/color]

                You can use std::cin which redirects input from stdin (your keyboard) to a
                string in your program. Example

                #include <string>

                int main()
                {
                std::string sInputString;
                // Wait for input from stdin (the keyboard)
                std::cin >> sInputString;

                // Print out to the screen what the user just input
                std::cout << "The user just input the following string: " <<
                sInputString << std::endl;
                }

                I hope this helps



                Comment

                • Jacob Jensen

                  #9
                  Re: [OT, welcome msg] getch() function

                  What is wrong with
                  std::cin >> SomeString;

                  Jacob



                  "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message
                  news:7kD1c.2081 6$aT1.18934@new sread1.news.pas .earthlink.net. ..[color=blue]
                  > "Pelo GANDO" <o0593m@hotmail .com> wrote in message
                  > news:c26ucq$qcb $1@news-reader2.wanadoo .fr...[color=green]
                  > > Sir,
                  > > How would you do[/color]
                  >
                  > [nonblocking input]
                  >[color=green]
                  > >in ISO standard C++...
                  > > I would like knwo from you...[/color]
                  >
                  > Like I said, it cannot be done with standard C++.
                  > You'll need to use an extension, such as the
                  > one you mentioned. However you should note
                  > that this will only work with that particular
                  > compiler, others will have their own way, if
                  > they have any at all. When you encounter this
                  > situation, I advise you to isolate and clearly
                  > identify such uses, so porting will be easier
                  > when the time comes.
                  >
                  > -Mike
                  >
                  >[/color]


                  Comment

                  • Rolf Magnus

                    #10
                    Re: [OT, welcome msg] getch() function

                    Mike Wahler wrote:
                    [color=blue]
                    > "Pelo GANDO" <o0593m@hotmail .com> wrote in message
                    > news:c26ucq$qcb $1@news-reader2.wanadoo .fr...[color=green]
                    >> Sir,
                    >> How would you do[/color]
                    >
                    > [nonblocking input][/color]

                    How would waiting for keyboard input be _non_blocking?

                    Comment

                    • Tor Husabø

                      #11
                      Re: wait for keyboard entry ?

                      Jacob Jensen wrote:
                      [color=blue][color=green]
                      >>What the code should be in C++ to wait for a keyboard entry in order to
                      >>execute the sequal of my program...
                      >>[/color]
                      >
                      >
                      > You can use std::cin which redirects input from stdin (your keyboard) to a
                      > string in your program. Example
                      >
                      > #include <string>
                      >
                      > int main()
                      > {
                      > std::string sInputString;
                      > // Wait for input from stdin (the keyboard)
                      > std::cin >> sInputString;
                      >
                      > // Print out to the screen what the user just input
                      > std::cout << "The user just input the following string: " <<
                      > sInputString << std::endl;
                      > }
                      >
                      > I hope this helps
                      >
                      >
                      >[/color]
                      This would require the user to press Enter before anything would happen,
                      and that's probably not good enough. (Assuming the 'Press any key to
                      continue' thing is what he's after.) :)

                      But printing 'Press Enter to continue.' and then reading from
                      std::cin could be a viable solution, although less elegant then
                      conio's getch() and the likes.

                      Tor

                      Comment

                      • Unforgiven

                        #12
                        Re: [OT, welcome msg] getch() function

                        Jacob Jensen wrote:[color=blue]
                        > What is wrong with
                        > std::cin >> SomeString;[/color]

                        Won't return until <enter> is pressed.

                        --
                        Unforgiven

                        Comment

                        Working...