Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. why no response to my cin input ?
Forum Updated to NodeBB v4.3 + New Features

why no response to my cin input ?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 5 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 13 Mar 2022, 02:02 last edited by Anonymous_Banned275
    #1

    Here is my FIRST usage of cout / cin using QT console.

    My code :

      char i;
        std::cout << " Hello...\n";
        std::cout << "Enter password: ";
        std::cin >> i;
        std::cout << "Password entered is " << i;
    

    and its output

    Hello...
    Enter password:q

    no response AFTER "q and enter key is pushed" - using debug console .

    What simple thing / setting am I missing ?

    There is a "Enter" key on keyboard I am pushing....

    S 1 Reply Last reply 14 Mar 2022, 09:07
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 13 Mar 2022, 04:22 last edited by
      #2

      two things:

      1. insert std::flush after your "Enter Password" prompt
      2. make i an std::string

      As for now seeing output, you should see output only after flushing cout.

      J 1 Reply Last reply 13 Mar 2022, 09:03
      0
      • K Kent-Dorfman
        13 Mar 2022, 04:22

        two things:

        1. insert std::flush after your "Enter Password" prompt
        2. make i an std::string

        As for now seeing output, you should see output only after flushing cout.

        J Offline
        J Offline
        JonB
        wrote on 13 Mar 2022, 09:03 last edited by
        #3

        @Kent-Dorfman said in why no response to my cin input ?:

        insert std::flush after your "Enter Password" prompt

        @AnneRanch
        Actually, after std::cout << "Enter password: "; is not where you need your std::flush() or std::endl. Because that is followed by a std::cin >> i; it auto-flushes, as you see in the output you show. You need it after your std::cout << "Password entered is " << i;, e.g.

        std::cout << "Password entered is " << i << std::endl;
        
        1 Reply Last reply
        0
        • A Anonymous_Banned275
          13 Mar 2022, 02:02

          Here is my FIRST usage of cout / cin using QT console.

          My code :

            char i;
              std::cout << " Hello...\n";
              std::cout << "Enter password: ";
              std::cin >> i;
              std::cout << "Password entered is " << i;
          

          and its output

          Hello...
          Enter password:q

          no response AFTER "q and enter key is pushed" - using debug console .

          What simple thing / setting am I missing ?

          There is a "Enter" key on keyboard I am pushing....

          S Offline
          S Offline
          SimonSchroeder
          wrote on 14 Mar 2022, 09:07 last edited by
          #4

          @AnneRanch said in why no response to my cin input ?:

          Here is my FIRST usage of cout / cin using QT console.

          What exactly do you mean with "Qt console"? I assume that you are using Qt Creator here. Is that right? Do you mean the integrated output pane of Qt Creator? Do you set Qt Creator to run the app in a separate terminal? What operating system are you using? Windows 10?

          In addition to the answers so far, this might play a role if @JonB's answer does not help so far.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tuan.dt1
            wrote on 16 Jun 2022, 13:47 last edited by
            #5

            You must tick run in terminal if you create CMake project with C++
            ae7dbd47-301b-42cd-a041-eb2468ae9fca-image.png

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved