首页 > 其他 > 详细

Practice5_1_string_Traversing

时间:2017-03-02 23:27:15      阅读:217      评论:0      收藏:0      [点我收藏+]

字符串中字符的遍历(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;
}

 

Practice5_1_string_Traversing

原文:http://www.cnblogs.com/liuzc/p/6492999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!