[ITK] itk::Point extraction operator
Wood, Tobias
tobias.wood at kcl.ac.uk
Mon Jan 18 05:19:56 EST 2016
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
More information about the Community
mailing list