I have a simple program that set unsigned int variable. Well, I have one problem. std::cout
works fine until InputCLI
is called.
First time program prints line when debugger reaches line that contain std::cout
std::cout << "debugNumber" << debugNumber;
After InputCLI
call program prints lines only with \n untill it reaches std::cin
operator. Whats wrong?
I'm coding in Eclipse (Linux). The moment before std::cin >> wait;
was executed:
#include <iostream>
#include <limits>
unsigned int InputCLI(unsigned int& x);
int main() {
int wait;
unsigned int debugNumber = 0;
std::cout << "debugNumber " << debugNumber;
std::cout << "Enter debug number\n";
InputCLI(debugNumber);
std::cout << "debugNumber\n";
std::cout << "debugNumber " << debugNumber;
if (debugNumber == 6) {
std::cout << "bubu";
}
std::cin >> wait;
return 0;
}
unsigned int InputCLI(unsigned int& x) {
if (std::cin >> x, std::cin.fail()) {
if (std::cin.bad() || std::cin.eof())
return -1;
std::cin.clear();
std::cin.ignore(std::numeric_limits < std::streamsize > ::max(), '\n');
return -2;
}
return 0;
}