My doubt is to skip a “.” from the input stream and read the whole number and the fractional parts in two different variables. Say I have an input like 10.26, I want store 10 in one variable a and 26 in another variable b.
In C, using scanf , I will do it like
scanf("%d.%d",&a,&b);
What is the equivalent way to do in C++ using cin? or should I include cstdio and use the scanf itself?
You can read the float as normal and use C-library’s
modffunction to split the number:Let
operator>>do the error checking!