-1

I want to align the text vertically, for horizontal alignment I use setw(n); Is there something like that only for vertical alignment? For example: Numbers are char type 123 456 789 I want to make vertical space between them. Is there a function to do that?

123

345

Mr. Hello_world
  • 85
  • 2
  • 10
  • Can you show an example or use case? What are you trying to print aligned? – Fantastic Mr Fox Aug 25 '15 at 18:42
  • This isnt really clear enough ... Is `123 456 ...` a string? Is it just numbers? Do you want this: `std::cout << "123\n456\n789\n";` ? – Fantastic Mr Fox Aug 25 '15 at 18:49
  • 1
    There is no notion of "vertical alignment" in C++, since you write left-to-right and emplace newlines as if they were just characters in one long line (which they are!). So you're going to have to be a lot of specific about what you want to do and why. – Lightness Races in Orbit Aug 25 '15 at 18:56
  • You'd need a pretty sharp, nonstandard console to handle that, and it's the nonstandard part that kills you. There is little support for nonstandard in the C++ standard. If you can't do it everywhere, it doesn't go in. This is why file system support is still experimental and you need compiler extensions for static-like definition of dynamic arrays. – user4581301 Aug 25 '15 at 19:39

1 Answers1

1

I don't think that there is an inbuilt function for this but you can use this function

            #include<iostream>
            void setv(char list[100]);
            int main()
            {
                char list[100]="1234 2345 3245 98";
                setv(list);
            return 0;
            }
            void setv(char list[100])
            {
                for(int i=0;i<strlen(list);i++)
                {
                    if(list[i]!=' ')
                    {
                        std::cout<<list[i];
                    }
                    else
                    {
                        std::cout<<"\n\n";
                    }

                }   
            }

This generates the below output:

    1234

    2345

    3245

If you are using turbo c or other basic compilers then "iostream" will become "iostream.h" and "std::cout<<" will become only "cout<<"

Vinay Ranjan
  • 294
  • 3
  • 14