How to convert string with two float numbers to two float numbers in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

int main()
{
	string s("873.92 3.14");
	string::size_type st;     

	float f1 = std::stof(s, &st);
	float f2 = std::stof(s.substr(st));
	
	cout << f1 << " , " << f2 << endl;
	
	return 0;
}

/*
run:

873.92 , 3.14

*/

 



answered May 11, 2018 by avibootz

Related questions

1 answer 126 views
1 answer 156 views
1 answer 95 views
1 answer 572 views
1 answer 101 views
...