📄 ex5_03.cpp
字号:
// Exercise 5.3 Using a do-while loop to count characters
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main() {
long count= 0L;
char ch;
cout << "Please enter a sequence of characters terminated by '#':" << endl;
// We have to read at least one character - even if it's '#' - so do-while is best
do {
cin >> ch;
++count;
} while (ch != '#');
// We do not count '#' as a character, so count must be adjusted
--count;
cout << "You entered " << count
<< " characters (not counting spaces and the terminal #)." << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -