Thread: Equivelatn erase() function of string?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Equivelatn erase() function of string?

    Hello, I need to make an equivelant function as of string.erase(...)

    Can someone help me?
    Thanks!
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Equivalent function???

    For what??? Your own string class?? A global function??

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Equivelatn function for sting.erase(..)

    I cant use string in a DLL as it crashes (discussed in a specific article)

    So I have to make my own erase function taht works like the strings one. Get it now?

    Any ideas?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Well...um...is this for a string class you have implemented?

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    You just need a wrapper function around the string::erase method.

    Try something like:

    Code:
    char* serase(const char * s, int pos, int n);
    {
      static string str(s);
      str.erase(pos, n);
      return str.c_str();
    }
    Notice that I have made the strng object static. This is important in maintaining the persistence of the return result.

    Alternatively, you copy the result into a string pointer passed by argument.


    Correction:

    I think you may be better doing this, because of the static nature of str.

    Code:
    char* serase(const char * s, int pos, int n);
    {
      static string str;
      str = s;
      str.erase(pos, n);
      return str.c_str();
    }
    Last edited by Davros; 10-15-2002 at 01:50 PM.

  6. #6
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Why not just use memset()?

    char myString[32];
    strcpy(myString, "Hello World!");

    cout << myString << endl;
    memset(myString, 0, strlen(myString));
    cout << myString << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM