It skips all whitespace (spaces, tabs, new lines, etc.) by default. You can either change its behavior, or use a slightly different mechanism. To change its behavior, use the manipulator noskipws
, as follows:
cin >> noskipws >> a[i];
But, since you seem like you want to look at the individual characters, I'd suggest using get
, like this prior to your loop
cin.get( a, n );
Note: get
will stop retrieving chars from the stream if it either finds a newline char (
) or after n-1 chars. It stops early so that it can append the null character (
) to the array. You can read more about the istream
interface here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…