|
-
Jun 23rd, 2000, 07:09 AM
#1
Thread Starter
Member
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?
-
Jun 23rd, 2000, 05:43 PM
#2
Monday Morning Lunatic
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
-
Jun 25th, 2000, 07:41 AM
#3
Dazed Member
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|