Recover Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttp://yahoo.com/

Valid RSS

get GPL
COST (GBP)
this unit 1.80
sub units 0.00
add licence
0
Strings

strtodouble vec

Converts a text comma or space seperated string of numbers into a double array
Controller: CodeCogs

buy now get GPL add to cart

Interface

C++

Strtodouble Vec

 
std::vector<double>strtodouble_vecconst char*str )
Converts a text string of numbers, with each number seperated by a comma or space, into a dynamically allocated double precision array.

Example

#include<stdio.h>
#include<codecogs/strings/strtodouble_vec.h>
int main()
{
  const char input[]="12.3,34.5,33 23 45.3 2";
  std::vector<double> ans=strtodouble_vec(input);
  for(int i=0;i<ans.size();i++)
    printf("\n [%d] = %lf",i,ans[i]);
}

Output

[0] = 12.300000
 [1] = 34.500000
 [2] = 33.000000
 [3] = 23.000000
 [4] = 45.300000
 [5] = 2.000000

Parameters

strA text string of numbers, separated with commas or spaces
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


 

Page Comments

bunbun68\′s Photo
30 Oct 11, 9:41PM
Slow and unsafe code
1) It is not necessary to precompute how many fields there are in the string. You can just append to the vector as you are going along.<p> 2) What happens if some fields cannot be converted to a double (e.g. empty fields)?<p> 3) Returning vectors by value is inefficient for C++03. For more modern c++, you can use boost::spirit with simpler and much much faster code.
 
 Format Excel Equations

  You must login to leave a messge