cout formatting not working sometimes

Hello fellow stressed out programmers.

I'm trying to format my text but it is not working as defined here is example.

expected output

     ***Menu***
     1- Option
     2- Option
     >


output i receive

***Menu***
    1- Option
    2- Option
   >


Here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <cstring>

int main() {
    int m_indentation = 1;
    int m_menuCount = 3;
    char* m_title = new char[11];
    strcpy(m_title, "***Menu***");

			//Print Title
			std::cout.width(m_indentation * 4);
			std::cout << m_title << std::endl;

			//Check for items
			if (m_menuCount > 0) {
				//Print Options
				for (int i = 0; i < m_menuCount; i++) {
					std::cout.width(m_indentation * 4);
					std::cout << i + 1 << "- " << std::endl;
				}

				//Print dialouge
				std::cout.width(m_indentation * 4);
				std::cout << "> ";
                       }

return 0;

}

//assume m_indentation is always a positive number defaulted to 0 or 1, 2,3...
//m_title is a c style char string 


Any help is always appreciated, blessings to all.

Last edited on
when in doubt, rtfm
http://www.cplusplus.com/reference/ios/ios_base/width/
The field width determines the minimum number of characters to be written (...)
If the standard width of the representation is shorter than the field width, the representation is padded with fill characters


not what you are trying to do
std::cout << std::string(indentation, ' ');
blessings to all

Gee, thanks, magic man.
Topic archived. No new replies allowed.