Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream> #include<string> #include<cstdlib> #include<sstream>
- using namespace std;
- int main() { // To convert from string to float use atof function // atof needs #include<cstdlib>
- string s = "1.5"; float v; v = atof(s.c_str());
- // To convert float-to string use ostringstream variable // ostringstream needs #include<sstream> // ostringstream variables are used in a similar way to cout // Then get the string from the ostringstream using .str float d = 1.55; string str; ostringstream ss; ss << d; str = ss.str();
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement