Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:08:51+00:00 2026-06-04T21:08:51+00:00

I have a function that is supposed to find the last bit of a

  • 0

I have a function that is supposed to find the last bit of a directory in a string. eg:
“C:\Lolcats\pie\ambulance\” should return “ambulance”. However it returns some strange characters ive never seen, like the male arrow-point symbol and some other weird stuff.

string App::getlastName(string cakes){
    //finds the name of the last folder in a directory
    string name;
    string temp;//popback all of temp into name to invert it
    cakes.pop_back();
    char i = cakes[cakes.length()-1];
    while (i != '\\'){
        temp.push_back(cakes[i]);
        cakes.pop_back();
        i = cakes[cakes.length()-1];
    }                           //-1?
    for (int j = 0; j<temp.length(); ++j){
        name.push_back(temp.back());
        temp.pop_back();
    }
    return name;
}

This is probably one of the worst functions i’ve ever written, but I can’t think of how else to wrangle the end off 🙁 Can someone help me please? 😀

Note that the function doesnt need to find the name of a file, it’ll just be folders.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:08:52+00:00Added an answer on June 4, 2026 at 9:08 pm

    If you remove the trailing \ off the string you can use a simple combination of rfind and substr to get the data you want.

    string substring = cakes.substr(cakes.rfind("\\") + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in my script that's supposed to take in a string
I have the following function that is supposed to trigger anytime one of the
I have two functions that are supposed to encrypt and decrypt a string but
I have a search function that is supposed to take all the keywords in
I have created a function that creates a dynamic string array with dynamic string
I have a class written in php that is supposed to find the labels
Suppose I have a function that returns a closure: sub generator { my $resource
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.