0

Can any body help me in converting a double value e.g. 0.000015 to string format in Xcode. so that i may use it as a string. In visual C++ we have to_string function but in Xcode it doesnt works. Regards

Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
khan
  • 531
  • 6
  • 29

2 Answers2

4

If you have a compiler supporting C++11, then std::to_string() is what you want.

jaredready
  • 2,398
  • 4
  • 23
  • 50
  • thanks but i used the upper answer, as in this case when i change it to c++11 it give me some other errors...so i used the first one...thanks and regards – khan Jan 15 '14 at 10:47
1

You can make your 'homebrew' to_string() function very easy using std::stringstream:

template<typename T>
std::string to_string(T value)
{
    std::ostringstream oss;

    oss << value;
    return oss.str();
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • Thanks alot Bro... It worked, Sorry for late replying...just tried it now... thanks – khan Jan 15 '14 at 10:40