Enviado em 25/05/2020 - 12:20h
Existe alguma forma de eu conseguir fazer o strftime aceitar minha variável string? Modificando apenas o comando strftime?std::string Registered;
strftime(Registered, 29, "%d/%m/%Y %H:%M", localtime(&CaptureTime));
Contacts.cpp:1216:13: error: cannot convert ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘char*’
1216 | strftime(Registered, 29, "%d/%m/%Y %H:%M", localtime(&CaptureTime));
| ^~~~~~~~~~
| |
| std::string {aka std::__cxx11::basic_string<char>}
#include <iostream>
#include <string>
int main() {
time_t Capture = time(0); // Pego Data/Hora Atual
std::string Data_Hora;
//strftime(Registered.c_str(), 29, "%d/%m/%Y %H:%M", localtime(&CaptureTime)); // error: invalid conversion from ‘const char*’ to ‘char*’
//strftime(Registered.data.str().c_str(), 29, "%d/%m/%Y %H:%M", localtime(&CaptureTime)); // error: invalid use of member function ‘const _CharT*
strftime((char*)Data_Hora.c_str(), 20, "%d/%m/%Y %T", localtime(&Capture)); // RESULTADO = 08/04/2019 20:57:13
std::cout << Data_Hora;
}