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. stupid question about std::cin

stupid question about std::cin

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 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.
  • J Offline
    J Offline
    Jerome Conus
    wrote on last edited by
    #1

    Hi ! I'm sure this is a stupid question, but, if I do this : char Buffer[10]; std::cin >> Buffer; How can I make sure that the input won't be longer than the buffer ? Jérôme

    J N 2 Replies Last reply
    0
    • J Jerome Conus

      Hi ! I'm sure this is a stupid question, but, if I do this : char Buffer[10]; std::cin >> Buffer; How can I make sure that the input won't be longer than the buffer ? Jérôme

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

      Use

      std::cin.read(Buffer,sizeof(Buffer));

      (caveat, this does not append and null terminating character.) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

      J 1 Reply Last reply
      0
      • J Jerome Conus

        Hi ! I'm sure this is a stupid question, but, if I do this : char Buffer[10]; std::cin >> Buffer; How can I make sure that the input won't be longer than the buffer ? Jérôme

        N Offline
        N Offline
        namaskaaram
        wrote on last edited by
        #3

        :~

        1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          Use

          std::cin.read(Buffer,sizeof(Buffer));

          (caveat, this does not append and null terminating character.) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

          J Offline
          J Offline
          Jerome Conus
          wrote on last edited by
          #4

          Thanks ! Jerome

          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