I am trying to do something like the following:
stringstream convert1(Model_str.substr(2, 12));
cout << (Model_str.substr(2, 12)) << endl; //output = 0.999999
convert1>>vertex1[VertexCounter];
cout << vertex1[VertexCounter] << endl; //output = 0
Is there a reason why it is not being precise to 6 decimal places when placing it into my array?
When you extract an
intfrom a stream with>>, it reads for as long as there are characters that could be considered part of anint. Integers do not allow for fractional parts, so there are no decimal points inintvalues. It read the0from the stream, stored it in yourvertex1array element (assumingvertex1is an array ofint), and left the remaining characters on the input buffer for a later read operation to consume.If you want to read a floating-point string from a stream, you at the very least need to read into a type that supports floating-point values, such as
floatordouble. Whether you get the precise value you expected is another matter. The target type you choose might not be able to represent the exact value you want it to.