cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Using cin.getline() to get char array
Using cin.getline() to get char array
Nov 3, 2014 at 9:57am UTC
KMagic
(47)
I have a short code like this to test the use of cin.getline(). I declared a char array consisting of 4 elements. However, when I enter four characters and press enter, only the first 3 characters were read. Why is it?
PHOTO:
http://s28.postimg.org/4luw96071/Untitled.png
Nov 3, 2014 at 10:08am UTC
rich1
(106)
One character is needed to store the null character (\0), which indicates the end of the string
Nov 3, 2014 at 10:09am UTC
MiiNiPaa
(8886)
Because you need a spare character for "endline" symbol.
Topic archived. No new replies allowed.