[vtkusers] vtkstd::string from string to numers

Jeff Baumes jeff.baumes at kitware.com
Mon Feb 22 14:28:22 EST 2010


If you are just dealing with converting single numbers, you can do

#include "vtkVariant.h"

...

std::string str = "123.40";
double val = vtkVariant(str).ToDouble();

Internally it is using stringstream. Using stringstream directly is of
course much more flexible.

Jeff

On Sat, Feb 20, 2010 at 8:53 AM, Giancarlo Amati
<ilferraresebono at hotmail.it> wrote:
> superb! Thanks!
> GC.
>
> ________________________________
> Date: Sat, 20 Feb 2010 08:47:11 -0500
> From: daviddoria+vtk at gmail.com
> CC: vtkusers at vtk.org
> Subject: Re: [vtkusers] vtkstd::string from string to numers
>
> On Sat, Feb 20, 2010 at 8:42 AM, Giancarlo Amati
> <ilferraresebono at hotmail.it> wrote:
>
> Hello Users,
>
> is thre any functions in the std::string  which converts strings into
> correspondent numbers?
>
> I mean "123.40" = double 123.40
>
> Many thanks.
> GC.
>
> You should use string streams:
>
> #include <sstream>
>   std::string strNumber = "23.4";
>   std::cout << "strNumber = " << strNumber << std::endl;
>   std::stringstream ss;
>   ss << strNumber;
>   double dNumber;
>   ss >> dNumber;
>   std::cout << "dNumber = " << dNumber << std::endl;
> Thanks,
>
> David
> ________________________________
> Troppe caselle di posta? Gestiscile da Hotmail!
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list