cin input not completely read in C++ -
i learning program c++ using book lippman et al fifth edition. have run code:
#include <iostream> #include "sales_item.h" int main() { int book; { std::cin>>book; std::cout<<book<<std::endl; } return 0; } the int book declaration on own. not sure created header file named "sales_item" within project. book not else. header file pops next code inside it:
#ifndef sales_item_h_included #define sales_item_h_included #endif // sales_item_h_included the goal of project input isbn, price , number of books sold , output supposed display total revenue isbn. however, when enter data, writes in output 9 digits.
i not pretend solve me. appreciate help, book recommendations , on.
should modify on own header file?
theres limit value int can hold. in 32-bits architecture, int can hold values ranging -2147483648 2147483647.
you "only" outputs 9 digits, trying store number big stored in int.
try using int64_t or handle serial number std::string.
int64_t can hold values -9223372036854775808 9223372036854775807 , should suffice store 13 digits of isbn.
Comments
Post a Comment