Back to Cosmos

README

code/languages/cpp/double_to_string/README.md

latest1014 B
Original Source

There are various ways of converting string to double in the C++ language; but before going into the ways, let me give you a quick intro to string and double.

C++ provides the programmers a wide variety of built-in as well as user defined data types. String and double are both data types but they differ in a few respects:

Double is a built-in/primitive data type while std::string is a part of the standard library that comes with the C++ compiler which can be used after including the string.h header file. String is a sequence of 0 or more characters while a variable of type double can hold floating point numbers upto 8 bytes.

Now we shall look into the various ways we can convert double to string in C++. The diferent ways are listed below:

  1. double to String using C++’s std::to_string
  2. double to String using ostringstream
  3. double to String/character array using sprintf
  4. double to String boost’s lexical_cast

Link to the article: https://iq.opengenus.org/convert-double-to-string-in-cpp/