trying to input a credit card then convert it to a string so I can work with each individual number, now when i do a number like 323213 it works, but if I do a number with 16 digits it gives me back "-858993460" which is junk
1 2 3 4 5 6 7 8 9 10 11 12
// Variables for Member function use.
long creditcard;
cout << "This machine accepts credit card only." << endl;
cout << "Available items: " << endl;
//display items from text file
cout << "Enter your credit card number: ";
cin >> creditcard;
string CreditString = to_string(creditcard);
cout << "Credit card as string " << CreditString << endl;
This blog tests 16 (yes, SIXTEEN) different ways to convert int to string, most with external libraries though. However what's interesting is that conversion via stringstream was faster than std::to_string though not as fast as sprintf + std::string, at least for int's: