-
cin and formating
We are now beginning C++
How do i format d string that cin is going to print to the screen.It's printing down some numbers like
12" ends: 2
8" ends: 1
1" end: 1
but i want it to align them so it's better formated(I belive we are suppose to use cin for now,but any help is appreciated)
Code:
while ( height > 0 ) {
for (int i = 12; i >= 2 && height != 0; i -= 2) {
if ( height >= i ) {
std::cout << i << "\" ends: " << height/i << std::endl;
height = height%i;
}
}
-
Are you looking for a way to line up what gets printed to the screen? Maybe try the following, and see if that is what you are looking for:
Code:
std::cout << i << "\" \tends:\t" << height/i << std::endl;
-
Formatting with cout is done by outputting certain fromatting characters. There are escape sequences: "\n" for example would print a newline. Above you saw the tab escape sequence. The \ starts an escape, so if you want to actually output the backslash, you need to use \\. You may also see the constant, "endl" get outputted between it's own set of insertion operators, and this has the same effect as the \n character in a string.
-