Thread: Output Manipulation

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    23

    Smile Output Manipulation

    Hi, I have a program that displays nodes in a datbase. The problem is a lot of the fields are too long when I display them. Is there a c+++ output mainpulator that when a field is displayed to only display lets say the first 7 characters of the string that may have more characters then that . Note: I'm not using a character array Im using the <string> class.

    Example:

    Mitsubishi Eclipse 2003 23.45

    to

    Mitsubi Eclipse 2003 23.45

    Note: I dont want to actuall change the string to have only 7 characters I just want it to display 7 characters
    Last edited by LostNotFound; 03-08-2003 at 07:51 PM.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    you may be able to use setprecision? setprecision(7).

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    The simplest way I can think of is to use the substring. I'm not sure what happens though if you try to do a substring of 7 characters on a string thats less than 7, you might get gibberish in which case you'd need to use an if statement to check for length first...
    Code:
    cout<<mystring.substr(0,7);

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    23
    Thanks PJYelton that works great with my linked list. Appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  4. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  5. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM