Cin.get() HELP

I am a little confused on how cin.get() works. if i were to enter a number like '345454', shouldnt it only print out the first three numbers. instead, i am getting only the first 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
using namespace std;

int main() {

	
	char x[34] ;

	cin.get(x,3);
	cout << x << endl;

	system("pause");
	return 0;
Last edited on
if i were to enter a number like '345454', shouldnt it only print out the first three numbers.

No, it will only retrieve n - 1 characters. So when n is equal to 3 you will only retrieve 2 characters.

Did you try finding and reading documentation for this standard function?

http://www.cplusplus.com/reference/istream/istream/get/
Topic archived. No new replies allowed.