Puoi fare direttamente così:
codice:
std::vector<char> vChar(&szTime[0],&szTime[30]);
oppure se è già dichiarato:
codice:
std::vector<char> vChar;
std::copy(&szTime[0],&szTime[30],std::back_inserter(vChar));
Anche se più elegante potrebbe essere:
codice:
void getDateTime(std::vector<char>& szTime)
{
time_t rawtime = time(NULL);
struct tm timeinfo;
gmtime_s(&timeinfo, &rawtime);
strftime(&szTime[0], szTime.size(), "%a, %d %b %Y %X GMT", &timeinfo);
}
std::vector<char> vChar(30);
getDateTime(vChar);
o in alternativa:
codice:
std::string getDateTime()
{
time_t rawtime = time(NULL);
struct tm timeinfo;
gmtime_s(&timeinfo, &rawtime);
std::string szTime(30,'');
strftime(&szTime[0], szTime.size(), "%a, %d %b %Y %X GMT", &timeinfo);
return szTime;
}
std::string vChar = getDateTime();