zoukankan      html  css  js  c++  java
  • 第三章

    1.

    关于string中是否结尾

    string:标准中未规定需要作为字符串结尾。编译器在实现时既可以在结尾加,也可以不加。(因编译器不同)

    但是,当通过c_str()或data()(二者在 C++11 及以后是等价的)来把std::string转换为const char *时,会发现最后一个字符是。但是C++11,string字符串都是以''结尾。

    2.

    string s;

    s.size()返回值是一个size_type类型。与机器类型无关的无符号类型,不要使用int类型了

    3.

    范围for语句

    string str("hello, world");

    for(auto c : str)

      cout << c << endl;

    for(auto &c : str)  //引用

      c = toupper(c);

    cout << str << endl;

    4.二分查找

       while(mid != end && *mid != sought)
       {
               if(sought < *mid)
                       end =mid;
               else
                       beg = mid + 1;
               mid = beg + (end - beg) / 2;
       }

    习题

    3.3

    类似is >> s的读取:string对象会忽略开头的空白并从第一个真正的字符开始,直到遇见下一空白为止。

    类似getline(is, s)的读取:string对象会从输入流中读取字符,直到遇见换行符为止。

    3.17

    using namespace std;
    
    int main()
    {
        vector<string> s;
        string word;
    
        while(cin >> word)
        {
                s.push_back(word);
    
        }
    
        for(auto &word : s)
        {
                for (auto & c : word)
                {
                        c = toupper(c);
                }
        }
    
        for (auto word : s)
                cout << word << endl;
        return 0;
    }
  • 相关阅读:
    http 事务
    URI、URL、URN
    媒体类型(MIME类型)
    资源
    WEB客户端和服务器
    如何解决新浪微博返回结果中的中文编码问题
    新浪微博 使用OAuth2.0调用API
    新浪微博 授权机制研究
    hmac库 密钥相关的哈希运算消息认证码
    ValueError: Expecting property name: line 1 column 1 (char 1)
  • 原文地址:https://www.cnblogs.com/11ys/p/14601892.html
Copyright © 2011-2022 走看看