也可以改为while(input[0])或while(cininput[0])
2019獨角獸企業重金招聘Python工程師標準>>>
<<c++ primer plus>>
// static.cpp -- using a static local variable
#include <iostream>
// constants
const int ArSize = 10;
// function prototype
void strcount(const char * str);
int main()
{
??? using namespace std;
??? char input[ArSize];
??? char next;
??? cout << "Enter a line:\n";
??? cin.get(input, ArSize);
??? while (cin)???? //也可以改為while(input[0])或while(cin&&input[0])
??? {
??????? cin.get(next);
??????? while (next != '\n')??? // string didn't fit!
??????????? cin.get(next);
??????? strcount(input);
??????? cout << "Enter next line (empty line to quit):\n";
??????? cin.get(input, ArSize);
??? }
??? cout << "Bye\n";
??? return 0;
}
void strcount(const char * str)
{
??? using namespace std;
??? static int total = 0;??????? // static local variable
??? int count = 0;?????????????? // automatic local variable
??? cout << "\"" << str <<"\" contains ";
??? while (*str++)?????????????? // go to end of string
??????? count++;
??? total += count;
??? cout << count << " characters\n";
??? cout << total << " characters total\n";
}
轉載于:https://my.oschina.net/libowen/blog/94457
總結
以上是生活随笔為你收集整理的也可以改为while(input[0])或while(cininput[0])的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LVS负载均衡-NET、DR模式配置
- 下一篇: 5.[BX]和Loop指令