-
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
-
you may be able to use setprecision? setprecision(7).
-
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);
-
Thanks PJYelton that works great with my linked list. Appreciate it.