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

9
  • 2
    Use std::ostringstream! Commented Jan 14, 2014 at 18:18
  • How about this? stackoverflow.com/questions/8495076/… Commented Jan 14, 2014 at 18:21
  • ostringstream take char value. How ever i want to convert double or long double value to String. Commented Jan 14, 2014 at 18:21
  • 'ostringstream take char value' No, that's wrong! You can use the output operator>>() for any primitive type as usual! Commented Jan 14, 2014 at 18:23
  • How can i use this, can you give example forexample my code is given on stackoverflow.com/questions/21118842/… Commented Jan 14, 2014 at 18:25

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
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 Comment

Thanks alot Bro... It worked, Sorry for late replying...just tried it now... thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.