std::stof in C++ Last Updated : 02 Aug, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report Parses string interpreting its content as a floating-point number, which is returned as a value of type float. Syntax : float stof (const string& str, size_t* idx = 0); float stof (const wstring& str, size_t* idx = 0); Parameters : str : String object with the representation of a floating-point number. idx : Pointer to an object of type size_t, whose value is set by the function to position of the next character in str after the numerical value. This parameter can also be a null pointer, in which case it is not used. Return Value : On success, the function returns the converted floating-point number as a value of type float. Below is the C++ implementation of std::stof : CPP // CPP code to convert floating // type number to string #include <bits/stdc++.h> int main() { // String to be parsed std::string str = "100.80"; // val to store parsed floating type number float val = std::stof(str); // Printing parsed floating type number std::cout << val; return 0; } Output: 100.8 CPP // CPP code to convert integer // type number to string #include <bits/stdc++.h> int main() { // String to be parsed std::string str = "1000"; // val to store parsed integer type number float val = std::stof(str); // Printing parsed integer type number std::cout << val; return 0; } Output: 1000 Comment More infoAdvertise with us Next Article std::stoi Function in C++ R Rohit Thapliyal Improve Article Tags : Misc C++ STL cpp-strings-library Practice Tags : CPPMiscSTL Similar Reads std::stoi Function in C++ The stoi() is a standard library function that turns a string into an integer. C++ programmers utilize the function, which stands for "string to integer," to obtain integers from strings. Additionally, the stoi() function can remove other components, such as trailing letters from the string. Syntax: 3 min read strstr() in C/C++ In C/C++, std::strstr() is a predefined function used for string matching. <string.h> is the header file required for string functions. This function takes two strings s1 and s2 as arguments and finds the first occurrence of the string s2 in the string s1. The process of matching does not incl 3 min read strcat() in C C strcat() function appends the string pointed to by src to the end of the string pointed to by dest. It will append a copy of the source string in the destination string. plus a terminating Null character. The initial character of the string(src) overwrites the Null-character present at the end of 2 min read std::string::data() in C++ The data() function writes the characters of the string into an array. It returns a pointer to the array, obtained from conversion of string to the array. Its Return type is not a valid C-string as no '\0' character gets appended at the end of array. Syntax: const char* data() const; char* is the po 2 min read std::quoted in C++ 14 std::quoted is an I/O manipulator function that was introduced in C++ 14 as the part of <iomanip> library. Its primary purpose is to handle the quoted string in the input and output operations. In this article, we will learn about the std::quoted manipulator, how it works and how to use it in 5 min read std::string class in C++ C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. The string class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.String vs Character ArrayStringChar 8 min read Like