#include <iostream>
int main(){
using namespace std;
cout << "Guess my love numbers in the range 1~10: ";
int n;
do{
cin >> n;
}
while (n != 7);
cout << "Yes, 7 is my favorite." << endl;
return 0;
}
5.4 基于范围的for循环(C++11)
5.5 循环和文本输入
使用cin.get()的循环文本输入
#include <iostream>
int main(){
using namespace std;
char ch;
int count = 0;
cout << "Enter characters, enter # to quit: " << endl;
cin.get(ch);
while (cin.fail() == false){
cout << ch;
++count;
cin.get(ch);
}
cout << endl;
cout << count << " characters read" << endl;
return 0;
}