[ITK] itk::Point extraction operator
Dženan Zukić
dzenanz at gmail.com
Mon Jan 18 11:25:00 EST 2016
Hi Tobias,
the >> operator is meant to be used for human provided input, while <<
operator tries to have a nice formatting. Correctly passing points through
streams was obviously not considered frequent/important use-case.
Regards,
Dženan
On Mon, Jan 18, 2016 at 5:19 AM, Wood, Tobias <tobias.wood at kcl.ac.uk> wrote:
> Hello,
>
> While trying to read an itk::Point from stdin, I noticed that the
> insertion and extraction operators are asymmetric. The insertion operator
> adds [] round the point and uses commas for delimiters. The extraction
> operator only expects numbers with white-space as the delimiter. Hence the
> following code:
>
> itk::Point<float, 3> A; A[0] = 1.; A[1] = 2.; A[2] = 3.;
> itk::Point<float, 3> B;
> std::stringstream stream;
> stream << A;
> stream >> B;
> std::cout << "A = " << A << std::endl;
> std::cout << "B = " << B << std::endl;
>
>
> Produces this as output:
>
> A = [1, 2, 3]
> B = [0, 0, 0]
>
>
> with no errors or exceptions thrown.
>
> Is this intended behaviour? It was counter-intuitive to me - but in my
> experience dealing with formatted input via the extraction operator is a
> complete pain so I can understand why it was written like this! I found an
> interesting workaround which involves a custom locale on this Stack
> Overflow page -
> http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring
>
> Best wishes,
> Toby
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160118/273ea69d/attachment-0001.html>
More information about the Community
mailing list