mercredi 24 juin 2015

C++11 for loop with cin>>buff;

i recently came across this code:

int count=0;
for(std::string buf; std::cin>>buf;) {
    count++;
}
std::cout << count;

  1. My doubt is what does this code do?
  2. how is the cin>>buf thing working in the condition part?
  3. isn't it going in an infinite loop?
  4. trying to write it in c++11 give me error for String, is std::string different from String, if so, then which header do i need for String

Aucun commentaire:

Enregistrer un commentaire