How to resynch cout and stdio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
bool toggle_sync()
{
    bool init;
    if (init = std::ios::sync_with_stdio())
        std::ios::sync_with_stdio(false);
    else std::ios::sync_with_stdio(true);
    if (init != std::ios::sync_with_stdio())
        return true;
    else return false;
}

int main()
{
    for (int x = 0; x < 3; ++x)
        {
            std::cout << "First its " << std::ios::sync_with_stdio() << std::endl;
            if (toggle_sync())
                std::cout << "Positive.\n" << std::flush;
            else std::cout << "Negative.\n" << std::flush;
            std::cout << "Now its " << std::ios::sync_with_stdio() << std::endl;
        }
    return 0;
}


gives me:

First its 1
Positive.
Now its 0
First its 0
Negative.
Now its 0
First its 0
Negative.
Now its 0

Process returned 0 (0x0)   execution time : 0.047 s
Press any key to continue.



how do I fix it?
Topic archived. No new replies allowed.