How does the setw
stream manipulator (space count) work? When there is one \t
, for example, I want to print a
with four spaces, so I use \t
and I compare \t
with setw
.
The code that I wrote:
# include <iostream>
# include <iomanip>
int main()
{
std::cout<<"\t"<<"a\n";
std::cout<<std::setw(9)<<"a\n";
return 0;
}
Output:
a // This is 1 '\t'
a // This is setw()
So what I thought was:
setw(18)
= \t\t
The code worked. But when I deleted the \n
, it did not become one straight line.
# include <iostream>
# include <iomanip>
int main()
{
std::cout<<"\t\t"<<"a\n";
std::cout<<std::setw(18)<<"a";
return 0;
}
It gives me this output:
a
a
What's wrong?