a major problem with the printf() and scanf() functions is getting the conversion specification corresponding to the parameters correct in particular when first learning C. e.g. %d for int
-
-
int data
-
printf("data %d\n", data);
-
when you have a long list of parameters of different types it is very easy to get the conversion specifications wrong and it prints garbage.
Scanf also requires the address of operator & for input of simple types
lots of students forget the &
C++ has the put to operator >> and get from operators <<
-
int data;
-
cin >> data;
-
cout << "data " << data << endl;
-
C++ looks at the paramter type (int in this case) and calls the correct version of the overloaded functions operator<<() and operator>>(). Makes life much simpler.
To avoid the problems associated with scanf() and printf() some C books provide libraries of IO functions like printInt() and readInt(). I don't like them prefering to teach C using the C++ << and >> operators for IO. There are pros (IO is easier) and cons, i.e. sooner or later students have to lean printf() and scanf()