A
Aaron Gray
Whats the best way to get the filename from a path using std::string and
using char[] ?
Many thanks in advance,
Aaron
using char[] ?
Many thanks in advance,
Aaron
To me it sounded more like asking for a standard library facility thatDaniel said:Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
Many thanks in advance,
Sound a lot like a homework problem... Start from the end of the string
and work your way forward looking for the path separator character.
std::string already has a member function to do it, and there is a
function in the <cstring> header to handle the char[].
Good luck.
Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
Pavel said:To me it sounded more like asking for a standard library facility thatDaniel said:Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
Many thanks in advance,
Sound a lot like a homework problem... Start from the end of the string
and work your way forward looking for the path separator character.
would do the job. Something like File::Spec in Perl or java.io.File in
Java or basename/dirname in shell, you know..
I guess, everybody's hearing is different.. I am programming in C++ for
some two decades and it is still a puzzle to me how the people in charge
of the standard library select priorities. BTW, does anybody know if
such a basic facility (working with file names) is going to be
standardized in C++0x? Or does that new semantics for square brackets
trample everything? (obviously the past decade was the decade of angle
brackets, but now the squares rule, I guess. If I am still around I may
learn whole new story about parentheses in C++1y -- how exciting!).
Daniel T. said:Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
Many thanks in advance,
Sound a lot like a homework problem... Start from the end of the string
and work your way forward looking for the path separator character.
std::string already has a member function to do it, and there is a
function in the <cstring> header to handle the char[].
Fred said:Daniel T. said:Aaron Gray said:Whats the best way to get the filename from a path using
std::string and using char[] ?
Many thanks in advance,
Sound a lot like a homework problem... Start from the end of the
string and work your way forward looking for the path separator
character.
std::string already has a member function to do it, and there is a
function in the <cstring> header to handle the char[].
This assumes that there is only one path separator.
It can be done with member functions of std:string, but it is much
better to use
specific OS functions.
Fred said:Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
This is not really a C++ question.
Fred said:This is not really a C++ question.Aaron Gray said:Whats the best way to get the filename from a path using
std::string and using char[] ?
It should be.
It should be.Fred said:messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
Pavel said:Daniel said:Aaron Gray said:Whats the best way to get the filename from a path using std::string and
using char[] ?
Many thanks in advance,
Sound a lot like a homework problem... Start from the end of the string
and work your way forward looking for the path separator character.
To me it sounded more like asking for a standard library facility that
would do the job. Something like File::Spec in Perl or java.io.File in
Java or basename/dirname in shell, you know..
I guess, everybody's hearing is different.. I am programming in C++ for
some two decades and it is still a puzzle to me how the people in charge
of the standard library select priorities. BTW, does anybody know if
such a basic facility (working with file names) is going to be
standardized in C++0x? Or does that new semantics for square brackets
trample everything? (obviously the past decade was the decade of angle
brackets, but now the squares rule, I guess. If I am still around I may
learn whole new story about parentheses in C++1y -- how exciting!).
-Pavel
and there is a function in the <cstring> header to handle the char[].
James said:Fred said:messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
James said:Fred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
It doesn't have to work everywhere.
It's not like current compilers
support all of the C++ standard. If you have some exotic system, you
just have to do something platform specific (like you have to do today).
Something like versioning could certainly be mapped to paths, e.g. look
at Clearcase.
tni said:James said:Fred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?This is not really a C++ question.It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
It doesn't have to work everywhere.
tni said:James said:Fred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
It doesn't have to work everywhere.
But it is a rather bad standard, if it is not implementable on some
systems. The C and C++ standards go to great lengths not to require
specific pointer formats, 32 bit ints, or IEEE floating point, because
it is known that important systems out there can't support it.
It would be really surprising if the language would then try to
standardize file names and directories.
Andy Champ said:Aaron Gray wrote:
My 2c worth:
I'd just like to remind you that in Japan on Windoze the currency
symbol(1) can be used as a path separator. And are those ascii or unicode
or what chars there?
(1) yen symbol, which I can't work out how to type so you'll all be able
to read it - a Y overstruck with an equals sign
Andreas said:tni said:James Kanze wrote:
Fred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
It doesn't have to work everywhere.
But it is a rather bad standard, if it is not implementable on some
systems. The C and C++ standards go to great lengths not to require
specific pointer formats, 32 bit ints, or IEEE floating point,
because it is known that important systems out there can't support
it.
You seem to suggest that by leaving lots of fundamental concepts
implementation-defined the standard becomes more usable or
something.
I'd say that, on the contrary, the only result of this
is that rather than parts of it being unusable on some exotic
systems it becomes unusable everywhere. What good is a standard
which doesn't even allow me to do the most elementary things like a
simple portable command line tool which takes a filename as
parameter and does some IO-operation with that file?
Me too, but only because so far the standard seems to have a history
of trying to weasel out of exactly the kind of ugly, low-level
abstractions a standard library should provide first and foremost
of all. Which pretty much forces developers to code outside of the
standard, e.g. using Qt, which (although primarily a GUI-abstraction
layer) does provide things like a _proper_ string class (efficient,
with fully-fledged interfaces to codecs, filesystem etc). In other
words exactly the kind of thing that's indispensable for a _usable_
standard library.
We'll see about C++0x. Personally, based on past experience, I'm not
holding my breath...
But it has Java (see same page) which incidentally has the standard APIBo said:Andreas said:You seem to suggest that by leaving lots of fundamental conceptstni wrote:
James Kanze wrote:
Fred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
It doesn't have to work everywhere.
But it is a rather bad standard, if it is not implementable on some
systems. The C and C++ standards go to great lengths not to require
specific pointer formats, 32 bit ints, or IEEE floating point,
because it is known that important systems out there can't support
it.
implementation-defined the standard becomes more usable or
something.
Yes, by not specifying everything down to the last bit, the language
is actually usable on a wider range of machines.
Another "totally portable" language needs special hardware add-ons to
run on some machines where C++ runs natively:
http://www-03.ibm.com/systems/z/advantages/zaap/index.html
I'd say that, on the contrary, the only result of this
is that rather than parts of it being unusable on some exotic
systems it becomes unusable everywhere. What good is a standard
which doesn't even allow me to do the most elementary things like a
simple portable command line tool which takes a filename as
parameter and does some IO-operation with that file?
What makes you think that you run command lines on all systems? Not
everything is a desktop.
Me too, but only because so far the standard seems to have a history
of trying to weasel out of exactly the kind of ugly, low-level
abstractions a standard library should provide first and foremost
of all. Which pretty much forces developers to code outside of the
standard, e.g. using Qt, which (although primarily a GUI-abstraction
layer) does provide things like a _proper_ string class (efficient,
with fully-fledged interfaces to codecs, filesystem etc). In other
words exactly the kind of thing that's indispensable for a _usable_
standard library.
Yes, Qt claims "Portability across desktop and embedded systems". What
about everyting else?
This system doesn't even have a GUI:
http://www-03.ibm.com/systems/z/hardware/
"Pavel" <dot_com_yahoo@paultolk_reverse.yourself> wrote in message
std::string filename = ...
size_t index = filename.find_last_of('/\\');
char moduleId[18]
filename.copy( moduleId, std::max( 18, filename.size() - index), index);
// throws out_of_rangeand there is a function in the <cstring> header to handle
the char[].
strrchr, problem is I want it to work on Unix and Windows.
Maybe, but how? To date, I don't think anyone has proposedFred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
There was a filesystem proposal for TR2 based on boost
implementation.http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html#He...
It wasn't included into C++0x.
There was a filesystem proposal for TR2 based on boostFred Zwarts wrote:
messageWhats the best way to get the filename from a path using
std::string and using char[] ?
This is not really a C++ question.
It should be.
Maybe, but how? To date, I don't think anyone has proposed
anything. (Remember, a standard solution would have to work
when the system didn't have sub-directories, or when it also had
version numbers and such.)
implementation.http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html#He...
It wasn't included into C++0x.
Maybe because it can't be implemented on some platforms, and
doesn't address all of the issues on others. Doing something
that is portable between Windows and Unix is relatively trivial,
but C++ aims to be portable to other systems as well.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.