adbarnet said:
You need to look at the iomanip library - setwidth, setprecision etc.
First, please don't top-post.
Second, unfortunately this is one of the serious omissions in the C++
streams, no setwidth or setprecision can help you read a field of any
*particular* width from a stream, so you have to use scanf for that or
resort to extracting fields into separate strings and reading them using
strtod or some such.
If you doubt the statement above, I dare you to write code to extract
two 4-digit integers from the stream that contains '12345678' so that
the first one would be 1234 and the second 5678. Simple, isn't it? I
will even help you:
#include <iostream>
#include <sstream>
#include <iomanip>
int main()
{
std::istringstream is("12345678");
int one, two;
????
std::cout << one << ' ' << two << std::endl;
}
Fill in the ???? with extraction from 'is' so that the output of this
programa is
1234 5678
(of course, simple ignoring all input and instead assigning values to
'one' and 'two' is considered cheating and is not acceptable). You're
free to add any headers at will, but if I read your claim correctly,
the ones that are already there should be enough...
V