Thread: Help with setw()

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Help with setw()

    so i need to set a width to output a word but i want the word to be cut off after a certain point...setw() doesn't cut the word of but only makes the space larger if the word is smaller

    but how do i cut the word of say at 5 characters?

    hopefully that makes sence

  2. #2
    Registered User
    Join Date
    Oct 2009
    Posts
    2
    here's my problem...


    Code:
    cout << setw(13) << artists[x] << setw(13) << titles[x]

    i want to cut off the output of artists[x] to only 13 letters even if it is longer...

    so the output would look like this

    The Beatl Yellow Subm


    what command do i need to do this?

    thanks!

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    If it is a std::string, I think you also need the substr method to make the cut.

    Code:
    cout << setw(13) << artists[x].substr(0, 13) << setw(13) << titles[x].substr(0, 13);
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Square ints, setw problem(not too hard ;))
    By Daniel Primed in forum C++ Programming
    Replies: 9
    Last Post: 01-19-2006, 03:25 PM
  2. Undefined setw() function
    By sononix in forum C++ Programming
    Replies: 4
    Last Post: 08-16-2004, 03:24 AM
  3. setw
    By RedRuM5746 in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2002, 08:02 PM
  4. Problem with setw
    By PJYelton in forum C++ Programming
    Replies: 3
    Last Post: 10-15-2002, 02:56 PM
  5. setw() and named constants
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 02-11-2002, 02:22 PM