Results 1 to 3 of 3

Thread: Two Questions With String

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Two Questions With String

    I'm using string.h and have two questions:

    1) What would be the easies way to make an array of strings? Something like:

    Code:
    string mystring[] = "dude","what's","up"
    Instead of declaring each of them one by one.

    2) I've seen alot of examples of a Trim() function using a char array, but I haven't seen any for string. Does anybody have an example?

    Thanks
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Trim would look like this:
    int first=s.find_first_not_of(32)
    return s.substr(s,first,s.find_last_not_of(32)-first);
    an array of strings
    string x[10];
    or a vector:
    vector<string> x;
    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

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks. I'll give it a try when I get home from work.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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