Fliping a string

This is a discussion on Fliping a string within the C++ Programming forums, part of the General Programming Boards category; Is there like a function that flips strings backwards? If not, how would you go about fliping a string? i ...

  1. #1
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483

    Fliping a string

    Is there like a function that flips strings backwards?

    If not, how would you go about fliping a string?

    i was thinking something like this:

    Code:
    for(int i = str.size(), z = 0; i > 0; i--, z++)
    {
        str2[z] = str[i];
    }
    The only problem with that is that I keep getting an error:

    Code:
    Debug Assertation Failed!
    
    Program: ...
    File: .\xstring
    Line: 1508
    
    Expression:  string subscript out of range
    
    For more information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
    Why! It only happens with Visual Studio 8 2005.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    There are a couple of problems with your code.
    The main one is that the index string.size() is one to high.
    Kurt
    edit: removed bull........

    and yes there is a standard way

    Code:
    reverse( str.begin(), str.end() );
    Last edited by ZuK; 12-07-2005 at 02:20 PM.

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Thank you.
    My Website
    010000110010101100101011
    Add Color To Your Code!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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