zoukankan      html  css  js  c++  java
  • Practice5_1_string_Traversing

    字符串中字符的遍历(Traversing)方式。

    // Practice5_string.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        /* 字符的遍历*/
        char* cArray = "2017/3/2 22:40";
        string str(cArray);
        //数组方式
        for(unsigned int i = 0; i < str.size(); i++)
        {
            cout << str[i] << " ";
        }
        cout << endl;
    
        //正向迭代器方式
        string::iterator it = str.begin();
        for(; it != str.end(); it++)
        {
            cout << *it << " ";
        }
        cout << endl;
    
        //反向迭代器方式
        string::reverse_iterator itReverse = str.rbegin();
        for(; itReverse != str.rend(); itReverse++)
        {
            cout << *itReverse << " ";
        }
        cout << endl;
    
        return 0;
    }
  • 相关阅读:
    [模板] 文艺平衡树
    [模板]平衡树splay
    [ZJOI2015]诸神眷顾的幻想乡
    [HAOI2016]找相同字符
    SP8093 JZPGYZ
    SP1812 LCS2
    SP1811 LCS
    AHOI2013 差异
    TJOI2015 弦论
    工艺(SAM)
  • 原文地址:https://www.cnblogs.com/liuzc/p/6492999.html
Copyright © 2011-2022 走看看