#include #include //for the standard library "string to integer" function stoi #include using namespace std; int main() { for (;;) { cout << "Input an integer in binary (or control-d to end): "; string s; cin >> s; //Attempt to input a string. if (!cin) { //If attempt was unsuccessful (i.e., control-d) break; //out of the loop } const int i {stoi(s, nullptr, 2)}; cout << "Binary " << s << " is decimal " << i << "\n\n"; } cout << "\n"; //Arrive here when user typed control-d return EXIT_SUCCESS; }