centering text for introduction

This is a discussion on centering text for introduction within the C++ Programming forums, part of the General Programming Boards category; what library do i need to use a function like setxy(x,y) to align my text, or are there any other ...

  1. #1
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41

    centering text for introduction

    what library do i need to use a function like setxy(x,y) to align my text, or are there any other funcions to do that out there as well?
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    This is implementation dependent, what compiler/OS do you use?

    -Prelude
    My best code is written with the delete key.

  3. #3
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    i use dev c++ 4.9.7 mingw 3.2 i beleive, and thanks for always helping prelude
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I believe Dev C++ supports the Win32 API. If so then this should work nicely.
    Code:
    #include <windows.h>
    
    void gotoxy (int x, int y )
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
    }
    -Prelude
    My best code is written with the delete key.

  5. #5
    PHP
    PHP is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    hm.. it says coord is undefined, any ideas or something i should have also done?
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >any ideas or something i should have also done?
    If you pasted the code exactly as I posted then it should work. There is another thing you can try though, if I remember correctly, your compiler does implement gotoxy in conio.h or conio.c. Try including one of them and see if you can use it. be sure to remove the function I gave you though.

    -Prelude
    My best code is written with the delete key.

  7. #7
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I tried the code, written by Prelude, and it worked fine using Dev C++ 4.
    none...

  8. #8
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    can't u just use setw() from iomanip.h?

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    if you do setw(), then you have to do a number of things to center.

    Code:
    #include <cstring.h>
    #include <iostream.h>
    #include <iomanip.h>
    
    main()
    {
        string name = "TITLE";
        int length;
    
        length = strlen(name.c_str())/2;
        cout << setiosflags(ios::right);
        cout << setw(40-length) << name << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21