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".
Try insert
:
int main() {
std::string s = "20190510";
s.insert(4, "/");
s.insert(7, "/");
std::cout << s << std::endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With