亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

c++ String去除頭尾空格的方法

 更新時(shí)間:2014年10月23日 10:43:07   投稿:shichen2014  
這篇文章主要介紹了c++ String去除頭尾空格的方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了c++ String去除頭尾空格的方法,分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

實(shí)現(xiàn)該功能可使用string的find_first_not_of,和find_last_not_of方法,具體實(shí)現(xiàn)帶如下:

復(fù)制代碼 代碼如下:
#include <iostream>
#include <string>

std::string& trim(std::string &);

int main()
{
    std::string s = " Hello World!! ";
    std::cout << s << " size:" << s.size() << std::endl;
    std::cout << trim(s) << " size:" << trim(s).size() << std::endl;

    return 0;
}

std::string& trim(std::string &s)
{
    if (s.empty())
    {
        return s;
    }

    s.erase(0,s.find_first_not_of(" "));
    s.erase(s.find_last_not_of(" ") + 1);
    return s;
}

希望本文所述對(duì)大家的C++程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論