zoukankan      html  css  js  c++  java
  • String

    void main()
    {
        char *buffer = new char(1000);
        memset(buffer, 0, 1000);
        char buffer1[1000] = {};
        buffer1[0] = 'a';
        buffer1[1] = 'b';
        buffer1[2] = 'c';
        strcpy(buffer, &buffer1[0]);
    
    /*-------------------------------------------------*/
        string str(buffer);
        string sub = str.substr(0, 3);
        cout << sub.c_str();  //打印abc 
        cout << sub; //打印abc
        cout << sub.back(); //打印c
    /*pop_back是删除的意思*/
    /*-------------------------------------------------*/
        vector<string> str1;    
        str1.push_back(&buffer[0]);  
        str1.push_back(&buffer[1]);
        str1.push_back(&buffer[2]);
        cout << str1.back(); //打印c
        str1.pop_back();
     //   cout << str1.data;
        cout << str1.back(); //打印bc
        str1.pop_back();
        cout << str1.back(); //打印abc
        str1.push_back(buffer1);
        cout << str1.back(); //打印abc 应该是按照地址打印的
        
    /*------------------------------------------------*/
        string str2;
        str2.push_back('a');
        cout << str2; //打印a
        str2.pop_back();
        cout << str2; //没有输出
    /*-------------------------------------------------*/
        char buffer3[] = "abcdefg";
        vector<string> str3;
        str3.push_back(buffer3);
        cout << str3.back(); //打印abcdefg
        
        return 0;
    }

    #include <string>
    #include <vector>
    #include <iostream>
    
    int main()
    {
        wchar_t test[][8] = { L"first", L"second", L"third", L"fourth" };
        std::vector<std::wstring> vectorOfStrings;
        wchar_t* bufferForStrings;
        size_t i, length = 4;
        for (i = 0; i < length; i++) {
            // copy some string to the buffer...
            bufferForStrings = test[i];
            vectorOfStrings.push_back(bufferForStrings);
        }
    
        for (auto s : vectorOfStrings) {
            std::wcout << s << std::endl;
        }
    
        return 0;
    }
  • 相关阅读:
    html笔记之表单标签
    删除重复字符
    OC点语法和变量作用域
    PHP-You don’t have permissions to access xxx on this server!
    从70周年阅兵式寻找使命
    做市场需要的智能眼镜可以赚钱
    《华为你学不会》读书笔记
    做智能眼镜是为了更方便地拍摄
    智能眼镜是头戴式摄像机
    DA14580_583_DK_II开发板入门笔记
  • 原文地址:https://www.cnblogs.com/strive-sun/p/14108381.html
Copyright © 2011-2022 走看看