下面的代码展示了两种解决方案(
std::to_string
和std::stringstream
),用于将int
类型的m_currentSoundTime
转换为std::string
。那么,std::to_string
和std::stringstream
哪个更快呢?// Compute current sound time in minute and convert to string
stringstream currentTime;
currentTime << m_currentSoundTime / 60;
m_currentSoundTimeInMinute = currentTime.str();
或者
m_currentSoundTimeInMinute = to_string( m_currentSoundTime / 60 );