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 ?
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 ...
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 ?
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
Thnx!