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

View versions (1)

Interface

#include <codecogs/strings/strtodouble_vec.h>

using namespace Strings;

Converts a text string of numbers, with each number seperated by a comma or space, into a dynamically allocated double precision array.

Example 1

#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

str
A text string of numbers, separated with commas or spaces
GPL Licence — free for non commercial use. See Licence details.