Thread: Limited input

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    Limited input

    Lets say I got a dummy char array

    char dummy[n]

    I want to

    cin >> dummy

    But as you can see if input has more than n characters program will crash . So I wonder is there a way to get first n characters and ignore the rest ?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can use getline

    http://www.cplusplus.com/ref/iostrea...m/getline.html

    Or you can do it the easy way, and just use std::string, and stop worrying about all the low-level, fixed size char array ickyness .

    http://www.msoe.edu/eecs/cese/resources/stl/string.htm
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    Talking

    Thnx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM