在NDK中寫一些東西,剛好遇到要把int、long 轉成string,原本是要用c++11的函數 to_string來自動轉格式, 編譯參數也指定c++11了,但是NDK就是說找不到這個函數,問問google大神才發現NDK沒有實作出全部的c++11特性出來,網路上剛好有人寫了一個函數就拿來用 程式碼如下:

#include <string>
#include <sstream>

template <typename T>
std::string to_string(T value)
{
    std::ostringstream os ;
    os << value ;
    return os.str() ;
}

int main()
{
    std::string perfect = to_string(5) ;
}

資料來源:http://stackoverflow.com/questions/947621/how-do-i-convert-a-long-to-a-string-in-c

 

arrow
arrow

    大衛的記事 發表在 痞客邦 留言(0) 人氣()