cin.sync vs cin.ignore

Apr 8, 2014 at 2:36am
Firstly, heres an example of how its being used.

1
2
3
4
5
6
7
8
    std::string stringOne, stringTwo;
    while(1){
        std::cin >> stringOne, stringTwo;
        std::cout << "First string: " << stringOne << "\n";
        std::cout << "Second string: " << stringTwo << "\n";
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cin.clear();
    }


The idea is to take two space delimited strings, and discard the rest of the input. For example, entering "one two three" would discard everything after "two". Both cin.ignore and cin.sync do the job, but I'm curious, whats the difference of them in this context?
Last edited on Apr 8, 2014 at 4:07am
Apr 8, 2014 at 4:03am
cin.ignore() works everywhere, cin.sync() only on Windows (and possible other systems that decided that it makes sense for it to behave that way)
Apr 8, 2014 at 4:07am
Easy, thanks.
Topic archived. No new replies allowed.