Home >Database >Mysql Tutorial >技巧:巧用数组减少if语句

技巧:巧用数组减少if语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:29:41986browse

/* * FileName: odd_or_even.cpp * Author: Antigloss at http://stdcpp.cn * LastModifiedDate: 2005-7-22 22:30 * Purpose: Tell if a given number is odd or even */ #include cstdlib // for EXIT_SUCCESS #include iostream #include limits // for nu

 /*
 * FileName:          odd_or_even.cpp
 * Author:            Antigloss at http://stdcpp.cn
 * LastModifiedDate:  2005-7-22 22:30
 * Purpose:           Tell if a given number is odd or even
 */

#include     // for EXIT_SUCCESS
#include
#include      // for numeric_limits

// flush the input buffer
inline void flush_stdin()
{
    std::cin.clear(); // clear error state of the stream
    // clear data left at the input buffer
    std::cin.ignore( std::numeric_limits::max(), '\n' );
} // end of flush_stdin

int main()
{
    long num;
    const char *msg[] = { "Even", "Odd" };

    for (;;) {
        std::cout

        if ( std::cin >> num ) {
            std::cout         } else {
            std::cin.clear(); // clear error state before reading from the input stream
            if ( std::cin.get() == 'q' ) {
                flush_stdin();
                break;
            }
            std::cerr         }
        flush_stdin();
    }

    std::cout     std::cin.get();
    return EXIT_SUCCESS;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:创建示例数据库Next article:vim技巧备忘