string erase function problems

This is a discussion on string erase function problems within the C++ Programming forums, part of the General Programming Boards category; I am writing a program that uses some simple string manipulation functions to process names. All is working fine, except ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    string erase function problems

    I am writing a program that uses some simple string manipulation functions to process names. All is working fine, except when I need to use the erase function. My understanding is that the format is as follows:

    myString.erase(position to start erasing, # of positions to erase)

    However, when I run my code (attached), it processes all the names correctly except when i need to use the erase function to trim the string. Not sure what I am doing wrong, or if this is enough code to determine error.

    Thanks for your help.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    forgot to attach

    here's the attached "code" excerpt
    Attached Files Attached Files

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    what value is in ncommaloc? I think it is being initialized with a none integer value,

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Value of nCommaLoc

    nCommaLoc is an integer value that displays the position of the comma in the string. If there is no comma, it is taken care of in an earlier section, so if it reaches the point where the code fails, it will have a valid integer value.

    I can submit the entire code if that would help.

    Thanks.

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    This simple test works for me in MSVC++ 6.0, so your usage of erase seems to be fine.
    Code:
    #include <iostream>
    #include <string>
    int main()
    {
    	std::string test = "This is a test, please.";
    	int nCommaPos = test.find_first_of(",");
    	test.erase(0, nCommaPos + 2);
    	std::cout << test << std::endl;
    	return 0;
    }
    Maybe more code would help, and what is the value of strName when the processName method first starts (on the time that erase fails)?

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Entire files

    Here's the code in it's entirety. There's a custom library (utildll) that we use to easily create menus and has some useful free functions also. If you want to execute the code as is, make sure to add 'utildll.lib" for the linker. It will throw a bunch of errors on the initial compile. After complie failure, simply copy the utildll files (3 of them) into the debug directory. Also, I am using Visual Studio 2003.NET (not sure if that makes any difference). Thanks again for your help.
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21