Re: remove of string
Mike wrote:
Thanks Stuart. Still something is wrong....VB.NET is so much easier
for strings....
Many thanks again
Michael
------
XPLMGetPluginInfo( XPLMGetMyID(), NULL,filepath, NULL,NULL);
std:: string str = filepath;
std::string::size_type n = str.find_last_of('/');
if(n == std::string::npos) {
str.replace(n,str.length(),"sounds/BAN11.wav");
}
alutLoadWAVFile((ALbyte*) str.c_str (), &format, &data, &size,
&freq, &loop);
That's because you didn't understand what I meant. The test
if(n == std::string::npos)
checks whether '/' is *not* found in str. If it's not, you need to
decide what to do (which is why I wrote "do something useful" in my
other post). That useful thing might be e.g. somehow constructing a
directory stem to use based on your knowledge of what the program's
doing, or throwing an exception, or... What you're doing is checking
whether there's a problem, and only trying to go ahead with the normal
code if there is -- something's clearly wrong there. You should go ahead
with the normal code if n != std::string::npos, and handle the case when
it is equal.
For example, something like:
std::string str = filepath;
std::string::size_type n = str.find_last_of('/');
// Throw if str does not contain '/'.
if(n == std::string::npos) throw BadFilePathException(str);
str = str.substr(0, n+1);
alutLoadWAVFile(static_cast<ALbyte*>(str.c_str()), &format, &data,
&size, &freq, &loop);
Regards,
Stu