c++ - What is wrong with this code? I need to convert string into float -


what wrong code? need convert string float. m2 has error in m2.length

#include <iostream> #include <string> #include <cstdlib> #include <sstream> using namespace std;  int main() {     float v2;     char *m2 = "1 23 45 6";     (int = 0; < m2.length(); i++) //to convert every element in m2 float     {         v2 = atof(&m2[i]);     }     printf("%.2f", v2);      system("pause");     return 0;  } 

i need convert each element in array can store them make operations

okay how use string stream extract numbers string vector?

#include <iostream> #include <iterator> #include <sstream> #include <vector>  int main() {     std::string input = "1 23 45 6";     std::stringstream ss(input);     std::istream_iterator<double> end;     std::vector<double> output(std::istream_iterator<double>(ss), end); } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -