Limited input

This is a discussion on Limited input within the C++ Programming forums, part of the General Programming Boards category; Lets say I got a dummy char array char dummy[n] I want to cin >> dummy But as you can ...

  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, 02: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, 04:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 04:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21