-5

cin.get なしで動作するように変更するにはどうすればよいですか?

void convert(int bit[],string &s)
{    
    char c = 0;
    for(int i = 0;i < 8;i++)
    {
        c = c+(bit[i] << i);
    }
    cin.get();
    cout << c;
}
4

1 に答える 1

0

It's not quite clear what you're even trying to do. You throw away the return value of cin.get(), so it's only effect is to extract a character from the input stream, and execute any side effects associated with extracting a character. (std::cout is tied to std::cin by default, so one of the side effects would be to flush std::cin.) If you want the flush, you can do it directly, e.g. std::cout.flush(), or simply std::cout << c << flush. Note, however that outputting a character may not do what you want. If you want to output the actual value of c, rather than interpreting it as an encoded character, you'll have to convert it to an integral type larger then char first. And of course, if plain char is signed, you may want to convert it to an unsigned char first, unless you're prepared to deal with negative values.

于 2013-03-24T19:08:20.257 に答える