How can I make a "return one directory" function?

Let us say I want to represent the current working directory as a std::string and I need to return one directory back. What is the most efficient way of implementing it you can think of?
My train of thought goes something around the lines of:
>make sure the passed std::string is a valid directory
>check whether the current working directory is the root, then return the root
>else return the current working directory but only to the char before the last '/'
Is there a better way of implementing this?
std::filesystem::current_path().string()
https://en.cppreference.com/w/cpp/filesystem/current_path
JLBorges, that's not exactly what I needed, but still, thank you.
What exactly do you mean by "return one directory"?

Are you wanting to get what the parent directory is for the current directory? If the current working dir is (Windows): C:\Dir_1_\Dir_2_ do you want C:\Dir_1_?

Take a gander at https://en.cppreference.com/w/cpp/filesystem/path under the decomposition section.
Thank you a million, George P, that's exactly what I needed.
Topic archived. No new replies allowed.