Results 1 to 6 of 6

Thread: Formatting Functions

  1. #1

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394

    Smile Formatting Functions

    Is there are format function in C++? I need to line up a character array to the left and save to a variable.

    e.g.

    format("Hi", " @@@@@@@") = " Hi";
    format("Bye"," @@@@@@@") = " Bye";

    Thanks for any help
    VS.NET 2003

    Need to email me?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    There's no format function in C++, but theres a variety of string functions to deal with character arrays, you can for instance do it as follows:
    PHP Code:
    chara"Hi";
    char c[10] = "        ";
    strcpy(c+10-strlen(a),a); 
    here's documentation on the string functions
    http://www.cplusplus.com/ref/cstring/index.html
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Look at the format modules in the attached code
    Attached Files Attached Files

  4. #4

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    Thanks for your replies

    Those work:8
    VS.NET 2003

    Need to email me?

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If there is no format function, then what is sprintf? Only because it's C that doesn't mean it's bad.

    Else look at stringstreams, they are very useful.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    yes:

    PHP Code:
    sprintf(str"%-30s""Hi"); // right align a string 
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width