I wrote the following code
#include< iostream>
using namespace std;
int main()
{
char a[30];
cin.read(a,10);
cout<<(cin.gcount());
system("pause");
return 0;
}
the output was 10, as expected .... but then I wrote the following code
#include< iostream>
using namespace std;
int main()
{
char a[30];
cin>>a;
cout<<(cin.gcount());
system("pause");
return 0;
}
I entered a "hello" that was saved in ... the output this time was 0 instead of 5 ... if cin.gcount () returns the number of bytes read in the last input operation, why is this difference
source
share