2013-04-08 71 views
0

控制台宽度;假设默认或成为...?

if(std::cin){ 
    decision = std::cin.get(); 

    if(std::cin.eof()) 
     throw CustomException("Error occurred while reading input\n"); 
}else{ 
    throw CustomException("Error occurred while reading input\n"); 
} 

清洗残留输入流上的

std::cin.ignore(COL_WIDTH, '\n'); // skip bad input 

COL_WIDTH读取从控制台输入是80作为通过Why is the default terminal width 80 characters?确定。我应该假设一个80个字符的控制台宽度,或者是一个更适合于cin.ignore的更大数字?

回答

2

您可以输入超过一行字符,即使它是80.
改为使用std::numeric_limits<std::streamsize>::max()