本文整理汇总了C++中std::filesystem::path::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ path::c_str方法的具体用法?C++ path::c_str怎么用?C++ path::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::filesystem::path
的用法示例。
在下文中一共展示了path::c_str方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_process
std::system_error run_process(const std::filesystem::path &filename, const std::vector<std::string> &argv,
const std::vector<std::string> &envp)
{
cpid = fork();
if (cpid == -1)
{
return std::system_error(std::make_error_code(std::errc(std::errno)));
}
if (cpid == 0)
{
std::vector<char *> arg;
arg.push_back(filename.c_str());
for (const auto &v : argv)
{
arg.push_back(v.c_str());
}
arg.push_back(nullptr);
std::vector<char *> env;
for (auto &e : envp)
{
env.push_back(e.c_str());
}
env.push_back(nullptr);
auto exec_error = execve(filename.c_str(), arg.data(), env.data());
perror("execve");
exit(EXIT_FAILURE);
}
else
{
attached = true;
}
return std::system_error(std::make_error_code(std::errc(0)));
}
示例2: InvalidOperationException
// The processPath ends with dotnet.exe or dotnet
// like: C:\Program Files\dotnet\dotnet.exe, C:\Program Files\dotnet\dotnet, dotnet.exe, or dotnet.
// Get the absolute path to dotnet. If the path is already an absolute path, it will return that path
fs::path
HOSTFXR_UTILITY::GetAbsolutePathToDotnet(
const fs::path & applicationPath,
const fs::path & requestedPath
)
{
LOG_INFOF(L"Resolving absolute path to dotnet.exe from '%ls'", requestedPath.c_str());
auto processPath = requestedPath;
if (processPath.is_relative())
{
processPath = applicationPath / processPath;
}
//
// If we are given an absolute path to dotnet.exe, we are done
//
if (is_regular_file(processPath))
{
LOG_INFOF(L"Found dotnet.exe at '%ls'", processPath.c_str());
return processPath;
}
// At this point, we are calling where.exe to find dotnet.
// If we encounter any failures, try getting dotnet.exe from the
// backup location.
// Only do it if no path is specified
if (requestedPath.has_parent_path())
{
LOG_INFOF(L"Absolute path to dotnet.exe was not found at '%ls'", requestedPath.c_str());
throw InvalidOperationException(format(L"Could not find dotnet.exe at '%s'", processPath.c_str()));
}
const auto dotnetViaWhere = InvokeWhereToFindDotnet();
if (dotnetViaWhere.has_value())
{
LOG_INFOF(L"Found dotnet.exe via where.exe invocation at '%ls'", dotnetViaWhere.value().c_str());
return dotnetViaWhere.value();
}
const auto programFilesLocation = GetAbsolutePathToDotnetFromProgramFiles();
if (programFilesLocation.has_value())
{
LOG_INFOF(L"Found dotnet.exe in Program Files at '%ls'", programFilesLocation.value().c_str());
return programFilesLocation.value();
}
LOG_INFOF(L"dotnet.exe not found");
throw InvalidOperationException(format(
L"Could not find dotnet.exe at '%s' or using the system PATH environment variable."
" Check that a valid path to dotnet is on the PATH and the bitness of dotnet matches the bitness of the IIS worker process.",
processPath.c_str()));
}
示例3: decrypt_file
void decrypt_file(
fs::path const & sourcefile,
fs::path const & destfile,
std::string_view password)
{
CryptoPP::FileSource source(
sourcefile.c_str(),
true,
new CryptoPP::DefaultDecryptorWithMAC(
(CryptoPP::byte*)password.data(), password.size(),
new CryptoPP::FileSink(
destfile.c_str())
)
);
}
示例4: sfStream
//------------------------------------------------------------
bool ofOpenALSoundPlayer::sfStream(const std::filesystem::path& path,vector<short> & buffer,vector<float> & fftAuxBuffer){
if(!streamf){
SF_INFO sfInfo;
streamf = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!streamf){
ofLogError("ofOpenALSoundPlayer") << "sfStream(): couldn't read \"" << path << "\"";
return false;
}
stream_subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_command (streamf, SFC_CALC_SIGNAL_MAX, &stream_scale, sizeof (stream_scale)) ;
if (stream_scale < 1e-10)
stream_scale = 1.0 ;
else
stream_scale = 32700.0 / stream_scale ;
}
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
stream_samples_read = 0;
}
int curr_buffer_size = BUFFER_STREAM_SIZE*channels;
if(speed>1) curr_buffer_size *= (int)round(speed);
buffer.resize(curr_buffer_size);
fftAuxBuffer.resize(buffer.size());
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_count_t samples_read = sf_read_float (streamf, &fftAuxBuffer[0], fftAuxBuffer.size());
stream_samples_read += samples_read;
if(samples_read<(int)fftAuxBuffer.size()){
fftAuxBuffer.resize(samples_read);
buffer.resize(samples_read);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= stream_scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(streamf,&buffer[0],curr_buffer_size/channels);
stream_samples_read += frames_read*channels;
if(frames_read<curr_buffer_size/channels){
fftAuxBuffer.resize(frames_read*channels);
buffer.resize(frames_read*channels);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for(int i=0;i<(int)buffer.size();i++){
fftAuxBuffer[i]=float(buffer[i])/32565.0f;
}
}
return true;
}
示例5: float
//------------------------------------------------------------
bool ofOpenALSoundPlayer::mpg123ReadFile(const std::filesystem::path& path,vector<short> & buffer,vector<float> & fftAuxBuffer){
int err = MPG123_OK;
mpg123_handle * f = mpg123_new(nullptr,&err);
if(mpg123_open(f,path.c_str())!=MPG123_OK){
ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): couldn't read \"" << path << "\"";
return false;
}
mpg123_enc_enum encoding;
long int rate;
mpg123_getformat(f,&rate,&channels,(int*)&encoding);
if(encoding!=MPG123_ENC_SIGNED_16){
ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): " << getMpg123EncodingString(encoding)
<< " encoding for \"" << path << "\"" << " unsupported, expecting MPG123_ENC_SIGNED_16";
return false;
}
samplerate = rate;
size_t done=0;
size_t buffer_size = mpg123_outblock( f );
buffer.resize(buffer_size/2);
while(mpg123_read(f,(unsigned char*)&buffer[buffer.size()-buffer_size/2],buffer_size,&done)!=MPG123_DONE){
buffer.resize(buffer.size()+buffer_size/2);
};
buffer.resize(buffer.size()-(buffer_size/2-done/2));
mpg123_close(f);
mpg123_delete(f);
fftAuxBuffer.resize(buffer.size());
for(int i=0;i<(int)buffer.size();i++){
fftAuxBuffer[i] = float(buffer[i])/32565.f;
}
duration = float(buffer.size()/channels) / float(samplerate);
return true;
}
示例6: Open
bool AudioSourceOJM::Open(std::filesystem::path f)
{
char sig[4];
ifile = std::make_shared<std::ifstream>(f.string(), std::ios::binary);
if (!ifile->is_open())
{
Log::Printf("AudioSourceOJM: unable to load %s.\n", f.c_str());
return false;
}
ifile->read(sig, 4);
switch (GetContainerKind(sig))
{
case M30:
parseM30();
break;
case OMC:
parseOMC();
break;
default:
return false;
}
ifile->close();
return true;
}
示例7:
static std::filesystem::path find_last_file_matching_pattern(const std::filesystem::path& pattern) {
std::filesystem::path last_match;
for(const auto& entry : std::filesystem::directory_iterator(u"", pattern.c_str())) {
if( std::filesystem::is_regular_file(entry.status()) ) {
const auto match = entry.path();
if( match > last_match ) {
last_match = match;
}
}
}
return last_match;
}
示例8: sfReadFile
// ----------------------------------------------------------------------------
bool ofOpenALSoundPlayer::sfReadFile(const std::filesystem::path& path, vector<short> & buffer, vector<float> & fftAuxBuffer){
SF_INFO sfInfo;
SNDFILE* f = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!f){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): couldn't read \"" << path << "\"";
return false;
}
buffer.resize(sfInfo.frames*sfInfo.channels);
fftAuxBuffer.resize(sfInfo.frames*sfInfo.channels);
int subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE){
double scale ;
sf_command (f, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
sf_count_t samples_read = sf_read_float (f, &fftAuxBuffer[0], fftAuxBuffer.size());
if(samples_read<(int)fftAuxBuffer.size()){
ofLogWarning("ofOpenALSoundPlayer") << "sfReadFile(): read " << samples_read << " float samples, expected "
<< fftAuxBuffer.size() << " for \"" << path << "\"";
}
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(f,&buffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): read " << frames_read << " frames from buffer, expected "
<< sfInfo.frames << " for \"" << path << "\"";
return false;
}
sf_seek(f,0,SEEK_SET);
frames_read = sf_readf_float(f,&fftAuxBuffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLogError("ofOpenALSoundPlayer") << "sfReadFile(): read " << frames_read << " frames from fft buffer, expected "
<< sfInfo.frames << " for \"" << path << "\"";
return false;
}
}
sf_close(f);
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
return true;
}
示例9: StaticBackground
StaticBackground(Interruptible* parent, std::filesystem::path Filename)
: BackgroundAnimation(parent), List(this)
{
Log::Printf("Using static background: %s\n", Filename.c_str());
List.AddToListIndex(Filename, "", 0);
}
示例10: if
void
HOSTFXR_UTILITY::GetHostFxrParameters(
const fs::path &processPath,
const fs::path &applicationPhysicalPath,
const std::wstring &applicationArguments,
fs::path &hostFxrDllPath,
fs::path &dotnetExePath,
std::vector<std::wstring> &arguments
)
{
LOG_INFOF(L"Resolving hostfxr parameters for application: '%ls' arguments: '%ls' path: '%ls'",
processPath.c_str(),
applicationArguments.c_str(),
applicationPhysicalPath.c_str());
arguments = std::vector<std::wstring>();
fs::path expandedProcessPath = Environment::ExpandEnvironmentVariables(processPath);
const auto expandedApplicationArguments = Environment::ExpandEnvironmentVariables(applicationArguments);
LOG_INFOF(L"Known dotnet.exe location: '%ls'", dotnetExePath.c_str());
if (!expandedProcessPath.has_extension())
{
// The only executable extension inprocess supports
expandedProcessPath.replace_extension(".exe");
}
else if (!ends_with(expandedProcessPath, L".exe", true))
{
throw InvalidOperationException(format(L"Process path '%s' doesn't have '.exe' extension.", expandedProcessPath.c_str()));
}
// Check if the absolute path is to dotnet or not.
if (IsDotnetExecutable(expandedProcessPath))
{
LOG_INFOF(L"Process path '%ls' is dotnet, treating application as portable", expandedProcessPath.c_str());
if (applicationArguments.empty())
{
throw InvalidOperationException(L"Application arguments are empty.");
}
if (dotnetExePath.empty())
{
dotnetExePath = GetAbsolutePathToDotnet(applicationPhysicalPath, expandedProcessPath);
}
hostFxrDllPath = GetAbsolutePathToHostFxr(dotnetExePath);
arguments.push_back(dotnetExePath);
AppendArguments(
expandedApplicationArguments,
applicationPhysicalPath,
arguments,
true);
}
else
{
LOG_INFOF(L"Process path '%ls' is not dotnet, treating application as standalone or portable with bootstrapper", expandedProcessPath.c_str());
auto executablePath = expandedProcessPath;
if (executablePath.is_relative())
{
executablePath = applicationPhysicalPath / expandedProcessPath;
}
//
// The processPath is a path to the application executable
// like: C:\test\MyApp.Exe or MyApp.Exe
// Check if the file exists, and if it does, get the parameters for a standalone application
//
if (is_regular_file(executablePath))
{
auto applicationDllPath = executablePath;
applicationDllPath.replace_extension(".dll");
LOG_INFOF(L"Checking application.dll at '%ls'", applicationDllPath.c_str());
if (!is_regular_file(applicationDllPath))
{
throw InvalidOperationException(format(L"Application .dll was not found at %s", applicationDllPath.c_str()));
}
hostFxrDllPath = executablePath.parent_path() / "hostfxr.dll";
LOG_INFOF(L"Checking hostfxr.dll at '%ls'", hostFxrDllPath.c_str());
if (is_regular_file(hostFxrDllPath))
{
LOG_INFOF(L"hostfxr.dll found app local at '%ls', treating application as standalone", hostFxrDllPath.c_str());
// For standalone apps we need .exe to be argv[0], dll would be discovered next to it
arguments.push_back(executablePath);
}
else
{
LOG_INFOF(L"hostfxr.dll found app local at '%ls', treating application as portable with launcher", hostFxrDllPath.c_str());
// passing "dotnet" here because we don't know where dotnet.exe should come from
// so trying all fallbacks is appropriate
if (dotnetExePath.empty())
{
dotnetExePath = GetAbsolutePathToDotnet(applicationPhysicalPath, L"dotnet");
}
//.........这里部分代码省略.........