zoukankan      html  css  js  c++  java
  • 参数命名要恰当,顺序要合理

    参数命名要恰当,顺序要合理。

     1 #include <iostream>
     2 #include <string>
     3 
     4 using namespace std;
     5 
     6 //测试字符串(string)对象
     7 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     8 
     9 int main(int argc, char** argv) {
    10         //创建string对象,并显示
    11     string s1="This";
    12     string s2="book.";
    13     cout<<"s1: "<<s1<<endl;
    14     cout<<"s2: "<<s2<<endl;
    15     
    16     //使用length成员函数
    17     cout<<"s1.length()="<<s1.length()<<endl;
    18     cout<<"s2.length()="<<s2.length()<<endl;
    19 
    20     //使用append成员函数
    21     s1.append(s2);
    22     cout<<"s1: "<<s1<<endl;
    23 
    24     //使用find成员函数和下标运算
    25     int pos=s1.find('b');
    26     cout<<"s1["<<pos<<"]="<<s1[pos]<<endl;
    27 
    28     //使用insert成员函数
    29     s1.insert(pos," is a ");
    30     cout<<s1<<endl;
    31 
    32     //使用assign成员函数
    33     s1.assign("Good");
    34     cout<<s1<<endl;
    35     return 0;
    36 }
  • 相关阅读:
    第二次结对作业
    第一次结对作业
    第二次个人编程
    第一次编程作业
    第一篇随笔
    个人总结
    第三次个人作业
    第二次结对作业
    第一次结对作业
    第二次编程
  • 原文地址:https://www.cnblogs.com/borter/p/9413547.html
Copyright © 2011-2022 走看看