📄 9_295_2.cpp
字号:
// 2.修改程序清单9.8:用string对象代替字符数组.这样,该程序将不再需要检查输入的字符串
// 是否过长,同时可以将输入字符串同字符串""进行比较,比判断是否为空行.
// static.cpp -- using a static local variable
#include <iostream>
#include <string>
void strcount (const std::string &str);
int main()
{
using namespace std;
string input;
cout<<"Enter a line: \n";
getline(cin, input);
while ("" !=input)
{
strcount (input);
cout<<"Enter next line (empty line to quit):\n";
getline(cin, input);
}
cout << "Bye\n";
return 0;
}
void strcount (const std::string &str)
{
using std::cout;
cout<<"\""<<str <<"\"contains";
int count = str.length();
cout << count << " characters\n";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -