print statement question

Hey all,

if you have an array of char p = "/file/a/"

how would you print that p to be like /a/file/?

I tried to reverse the string but ended up like /a/elif/ which is not what I want.

Thanks in advance,
The key is clearly the delimiting character '/'.

There are many ways to approach this. You could do it by stepping through the string one character at a time and testing for the delimiter, and so on. But this is a reasonably common type of string-parsing operation, it is easier to adapt a ready-made solution rather than re-invent the wheel.

Given that this is a c++ forum, I'd suggest using a stringstream and getline with a specified delimiter of '/'. Then each extracted part would be a string in its own right, you just need to re-assemble the parts to make up a new string in the required order.
Topic archived. No new replies allowed.