code1
std::istream &func1(std::istream &in) {
auto old_state = in.rdstate();
std::cout << old_state << std::endl;
std::string s;
while(in >> s) {
std::cout << s << std::endl;
}
in.setstate(old_state);
std::cout << in.rdstate() << std::endl;
//in.clear();
return in;
}
when execute this function, the output: 0 1 1 6 // ctrl+d 6
code2
std::istream &func2(std::istream &in) {
auto old_state = in.rdstate();
std::cout << old_state << std::endl;
std::string s;
while(in >> s) {
std::cout << s << std::endl;
}
in.setstate(old_state);
std::cout << in.rdstate() << std::endl;
in.clear();
return in;
}
when execute this function, the output: 0 1 1 6 // ctrl+d 0
I know the clear() reset the condition values in stream to valid state.But in func1, I have used setstate(old_state), why the output is still 6?
Aucun commentaire:
Enregistrer un commentaire