如果给定日期为2020年1月28日,那么在c ++中如何使用修整函数只能得到28

问题描述 投票:0回答:1

下面的代码不是修剪日期字符串。

string today_date = iGLib :: Trim(date,'/');

例如:今天的日期是“ 27/01/2020”所以我只想要27或01

我怎么只能在C ++中得到它。

c++ date trim
1个回答
0
投票

使用split(date, '/')

std::vector<std::string> split(const std::string& s, char delimiter)
{
   std::vector<std::string> tokens;
   std::string token;
   std::istringstream tokenStream(s);
   while (std::getline(tokenStream, token, delimiter))
   {
      tokens.push_back(token);
   }
   return tokens;
}

取自here

© www.soinside.com 2019 - 2024. All rights reserved.