Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ok... quick and easy... cin.flush();

ok... quick and easy... cin.flush();

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 0 Views 1 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.
  • S Offline
    S Offline
    SilverShalkin
    wrote on last edited by
    #1

    i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:

    C J A 3 Replies Last reply
    0
    • S SilverShalkin

      i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'm sorry, it's cout that requires the .flush(); :-O The reason is that one needs to be cleared before you use the other. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

      1 Reply Last reply
      0
      • S SilverShalkin

        i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        Try with cin.clear(), which should reset cin in case you had a formatting error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        S 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          Try with cin.clear(), which should reset cin in case you had a formatting error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          S Offline
          S Offline
          SilverShalkin
          wrote on last edited by
          #4

          ok... that makes more sense... cin.clear(); but is that all? the line works but the program comes acrros the same thing... after you insert the GPA of the student "GPA is a float" the program prints the name and the gpa, then it asks for the name again, but when you press enter after the name, the program atomatically inserts the previouse GPA. thanks again.. "If i figuere it out, ill post :)" ~SilverShalkin :rose:

          1 Reply Last reply
          0
          • S SilverShalkin

            i asked a question refering to why my cin stopped working after the program had looped, my answer was cin.flush(); I applied that line to my code, and the program didnt reconize it,... if this is the way to reinitialize a cin for it works everytime the loop goes through, then why wont it work? is there a required header? painless see? thanks! ~SilverShalkin :rose:

            A Offline
            A Offline
            Abin
            wrote on last edited by
            #5

            That's because of the new line (character "\n") that you entered in previous cin, to fix this problem simply add statement "cin.ignore(1, '\n');" before the second use of cin. Example: int x; float y; cin >> x; // first call, fine cin.ignore(1, '\n'); // this is a must cin >> y; // now there's no problem

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups