gpt4 book ai didi

c++ - 在 C++ 中拆分 `char[]`

转载 作者:行者123 更新时间:2023-11-30 00:40:24 24 4
gpt4 key购买 nike

我有一个 YYYYMMDDHHMMSS 格式的 char[]

例如2011052504572

我想从这个字符中检索年、月、日、小时、分钟和秒。我该怎么做?

注意:我不能使用任何第三方 dll。

谢谢,西德

最佳答案

如果您使用的是 STL,则只需将字符串放入 std::string 并使用 substr 方法:

std::string dateTime=......;

std::string year=dateTime.substr(0,4);
std::string month=dateTime.substr(4,2);
// etc
// etc

关于c++ - 在 C++ 中拆分 `char[]`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6136033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com