Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string representing date and transform it

To format a string representing date received from other part some transform is required:

source:
    std::string s = "20190510";
target:
    std::string t = "05/10/2019";

One way is to copy char by char, is there an elegant way to do it beautiful and fast?

UPDATE: Sorry the transform should be from "yyyymmdd" to "mm/dd/yyyy".

like image 733
fluter Avatar asked May 10 '19 06:05

fluter


1 Answers

Try insert:

int main() {
    std::string s = "20190510";
    s.insert(4, "/");
    s.insert(7, "/");
    std::cout << s << std::endl;
}
like image 126
Blaze Avatar answered Sep 27 '22 23:09

Blaze