Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include​<iostream> #include​<string> #include​<cstdlib> #include​<sstream>
  2. using namespace​ ​std;
  3. int ​main() { // To convert from string to float use atof function // atof needs #include<cstdlib>
  4. string ​s = ​"1.5"​; float​ ​v; v = atof(s.c_str());
  5.  
  6. // 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();
  7.  
  8. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement