Results 1 to 3 of 3

Thread: Manipulating char variables

  1. #1

    Thread Starter
    Member
    Join Date
    May 1999
    Location
    San Jose, CA, USA
    Posts
    43

    Arrow

    What are some of the functions (with syntax) for manipulating char variables? Like in VB there's trim() and mid() and left() and all those great functions... what would i do in c++ to accomplish these types of functions?
    -_=Progrium=_-
    Progrium Software

    Using: VB 6 Pro

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    don't you mean char*?
    at the moment, for pure operations on char arrays, then string.h has some useful things, all beginning with str.
    If you want ease of use, try the STL string class:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void main() {
        string sMyStr = "A string";
        cout << sMyStr << endl;
    }
    there's lots of member functions to do what you need - the documentation's pretty good.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    #include <string.h>

    // example of using some string functions

    class Cmessage {
    char* pmessage //pointer to object text string

    public:
    // function to display message

    void showit();
    {
    cout << endl << pmessage;
    }
    // constructor defination

    Cmessage(const char* text = "default message")
    {
    pmessage = new char[strlen(text) + 1]; // allocate space
    // for text
    strcpy(pmessage,text); // copy text to new memory

    ~Cmessage(); //destructor protype
    };






    // deconstructor to free up memory created by new
    Cmessage::~Cmessage()
    {
    cout << "destructor called"; // just to track what happens
    << endl;
    delete[] pmessage; // free memory assigned to pointer
    }


    "A man ought to read as inclination leads him for what he reads as a task will do him little good"


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