Code:
#include <iostream>
#include <iomanip>
using namespace std;
int i, j;
int main()
{
cout << "12345"<< endl;
cout << setw(7)<< endl;
cout << "12345"<< endl;
cout << "12345"<< endl;
cout << "12345"<< endl;
cout << setw(7)<< "K" << endl;
cout << "12345"<< endl;
cout << "12345"<< endl;
cout << "12345"<< endl;
return 0;
}
compiles this:
Code:
12345
12345
12345
12345
K
12345
12345
12345
Press any key to continue . . .
In the second box of code, the second set of numbers is indented 2 spaces which is equal to the setw(7). What I don't understand is why it does this. In the first box of code, just having cout << setw(7)<<endl; looks like it does a whole line skip and then continues to use the setw(7) on the next line after that endl; command. I would think the endl; would end any setw but it doesn't appear to. Is there a rule of why it does this?