• 202006XX-静态存储持续性\无连接性


    //static.cpp-using a static local variable
    #include <iostream>
    using namespace std;
    //constants 常量
    const int ArSize=10;
    //function prototype 函数原型
    void strcount(const char * str);
    int main()
    {
    char input[ArSize];
    char next1;
    cout<<"enter a line: ";
    cin.get(input,ArSize);
    //cin.get和cin.getline的区别是:cin.get最后一位取的是换行符,所以只能取9位,但在dev中好像都一样,input是取的结果 ,而cin的值是16进制
    while(cin)
    {
    cin.get(next1);
    cout<<next1<<endl; //读取行输入后的字符
    while(next1!=' ')
    cin.get(next1);
    strcount(input);
    cout<<"Enter next line(empty lint to quit): ";
    cin.get(input,ArSize);
    }
    cout<<"bye ";
    return 0;
    }
    void strcount(const char * str)
    {
    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 ";
    cout<<total<<"total characters ";
    }

  • 相关阅读:
    VB6SP6极度精简兼容绿色版
    Upnp资料整理
    RevMan简单入门指南
    小程序 --flex
    IV
    2017-10-27错误日志
    170616_2
    170616
    2017-06-07
    111111112222
  • 原文地址:https://www.cnblogs.com/whcsrj/p/13033326.html
Copyright © 2020-2023  润新知