2 doubles

Hi, I have 361 two double integers stored as a list in a .txt file. When i run the programme the first double integer joins the second double integer on the same line which I don't want. Anyone know how to fix this?
What's a double integer? Can you give a sample on what your file looks like?
int rowCounter = 1;
double var1;
double var2;

inputFile >> var1;
inputFile >> var2;

while (!inputFile.fail())
{

cout << setw(3) << rowCounter;
cout << " " << setw(3) << var2;
cout << " " << setw(3) << var1;

rowCounter++;
First of all, variables of type double are real number (with decimal places), not integers. They are really double floats, not double ints.

But to answer your question, you need to write a new line between your variable prints. You do this by using the endl statement.

1
2
cout << " " << setw(3) << var2 << endl;
cout << " " << setw(3) << var1;


For correctness, endl is actually a function taking a single argument that is inserted into a stream, but you'll learn about that as you get more experience with C++.

The cout stream and the endl function are both found in <iotream> within the std namespace, so they would correctly be called std::cout and std::endl.
Topic archived. No new replies allowed.